summaryrefslogtreecommitdiff
path: root/numpy/testing
diff options
context:
space:
mode:
authorBrigitta Sipőcz <bsipocz@gmail.com>2022-05-20 19:47:26 -0700
committerBrigitta Sipőcz <bsipocz@gmail.com>2022-05-23 09:29:59 -0700
commite8dda96dd2a50d2e23134d924cbcabd545af54a1 (patch)
treed6b1ee56cd672ae95d08c26ab8a3356dc6e235d7 /numpy/testing
parent66ec23b97e7145747410c838edaead0f7cfa7b2e (diff)
downloadnumpy-e8dda96dd2a50d2e23134d924cbcabd545af54a1.tar.gz
MAINT: Fix warningc context tests, uncover bug?
Diffstat (limited to 'numpy/testing')
-rw-r--r--numpy/testing/tests/test_utils.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py
index 7b326365d..6fa51454f 100644
--- a/numpy/testing/tests/test_utils.py
+++ b/numpy/testing/tests/test_utils.py
@@ -1294,17 +1294,23 @@ def test_clear_and_catch_warnings():
warnings.simplefilter('ignore')
warnings.warn('Some warning')
assert_equal(my_mod.__warningregistry__, {})
- # Without specified modules, don't clear warnings during context
+ # Without specified modules, don't clear warnings during context.
+ # catch_warnings doesn't make an entry for 'ignore'.
with clear_and_catch_warnings():
warnings.simplefilter('ignore')
warnings.warn('Some warning')
- assert_warn_len_equal(my_mod, 1)
+ assert_warn_len_equal(my_mod, 0)
+
+ # Manually adding two warnings to the registry:
+ my_mod.__warningregistry__ = {'warning1': 1,
+ 'warning2': 2}
+
# Confirm that specifying module keeps old warning, does not add new
with clear_and_catch_warnings(modules=[my_mod]):
warnings.simplefilter('ignore')
warnings.warn('Another warning')
- assert_warn_len_equal(my_mod, 1)
- # Another warning, no module spec does add to warnings dict, except on
+ assert_warn_len_equal(my_mod, 2)
+ # Another warning, no module spec does add to warnings dict
with clear_and_catch_warnings():
warnings.simplefilter('ignore')
warnings.warn('Another warning')
@@ -1350,11 +1356,15 @@ def test_suppress_warnings_module():
warnings.warn('Some warning')
assert_warn_len_equal(my_mod, 0)
+ # Manually adding two warnings to the registry:
+ my_mod.__warningregistry__ = {'warning1': 1,
+ 'warning2': 2}
+
# Without specified modules, don't clear warnings during context
with suppress_warnings():
warnings.simplefilter('ignore')
warnings.warn('Some warning')
- assert_warn_len_equal(my_mod, 1)
+ assert_warn_len_equal(my_mod, 2)
def test_suppress_warnings_type():
@@ -1378,11 +1388,15 @@ def test_suppress_warnings_type():
warnings.warn('Some warning')
assert_warn_len_equal(my_mod, 0)
+ # Manually adding two warnings to the registry:
+ my_mod.__warningregistry__ = {'warning1': 1,
+ 'warning2': 2}
+
# Without specified modules, don't clear warnings during context
with suppress_warnings():
warnings.simplefilter('ignore')
warnings.warn('Some warning')
- assert_warn_len_equal(my_mod, 1)
+ assert_warn_len_equal(my_mod, 2)
def test_suppress_warnings_decorate_no_record():