From e8dda96dd2a50d2e23134d924cbcabd545af54a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brigitta=20Sip=C5=91cz?= Date: Fri, 20 May 2022 19:47:26 -0700 Subject: MAINT: Fix warningc context tests, uncover bug? --- numpy/testing/tests/test_utils.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'numpy/testing') 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(): -- cgit v1.2.1