()
| 1300 | |
| 1301 | |
| 1302 | def test_clear_and_catch_warnings(): |
| 1303 | # Initial state of module, no warnings |
| 1304 | my_mod = _get_fresh_mod() |
| 1305 | assert_equal(getattr(my_mod, '__warningregistry__', {}), {}) |
| 1306 | with clear_and_catch_warnings(modules=[my_mod]): |
| 1307 | warnings.simplefilter('ignore') |
| 1308 | warnings.warn('Some warning') |
| 1309 | assert_equal(my_mod.__warningregistry__, {}) |
| 1310 | # Without specified modules, don't clear warnings during context. |
| 1311 | # catch_warnings doesn't make an entry for 'ignore'. |
| 1312 | with clear_and_catch_warnings(): |
| 1313 | warnings.simplefilter('ignore') |
| 1314 | warnings.warn('Some warning') |
| 1315 | assert_warn_len_equal(my_mod, 0) |
| 1316 | |
| 1317 | # Manually adding two warnings to the registry: |
| 1318 | my_mod.__warningregistry__ = {'warning1': 1, |
| 1319 | 'warning2': 2} |
| 1320 | |
| 1321 | # Confirm that specifying module keeps old warning, does not add new |
| 1322 | with clear_and_catch_warnings(modules=[my_mod]): |
| 1323 | warnings.simplefilter('ignore') |
| 1324 | warnings.warn('Another warning') |
| 1325 | assert_warn_len_equal(my_mod, 2) |
| 1326 | |
| 1327 | # Another warning, no module spec it clears up registry |
| 1328 | with clear_and_catch_warnings(): |
| 1329 | warnings.simplefilter('ignore') |
| 1330 | warnings.warn('Another warning') |
| 1331 | assert_warn_len_equal(my_mod, 0) |
| 1332 | |
| 1333 | |
| 1334 | def test_suppress_warnings_module(): |
nothing calls this directly
no test coverage detected