MCPcopy Index your code
hub / github.com/numpy/numpy / test_clear_and_catch_warnings

Function test_clear_and_catch_warnings

numpy/testing/tests/test_utils.py:1774–1803  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1772
1773@pytest.mark.thread_unsafe(reason="checks global module & deprecated warnings")
1774def test_clear_and_catch_warnings():
1775 # Initial state of module, no warnings
1776 my_mod = _get_fresh_mod()
1777 assert_equal(getattr(my_mod, '__warningregistry__', {}), {})
1778 with clear_and_catch_warnings(modules=[my_mod]):
1779 warnings.simplefilter('ignore')
1780 warnings.warn('Some warning')
1781 assert_equal(my_mod.__warningregistry__, {})
1782 # Without specified modules, don't clear warnings during context.
1783 # catch_warnings doesn't make an entry for 'ignore'.
1784 with clear_and_catch_warnings():
1785 warnings.simplefilter('ignore')
1786 warnings.warn('Some warning')
1787 assert_warn_len_equal(my_mod, 0)
1788
1789 # Manually adding two warnings to the registry:
1790 my_mod.__warningregistry__ = {'warning1': 1,
1791 'warning2': 2}
1792
1793 # Confirm that specifying module keeps old warning, does not add new
1794 with clear_and_catch_warnings(modules=[my_mod]):
1795 warnings.simplefilter('ignore')
1796 warnings.warn('Another warning')
1797 assert_warn_len_equal(my_mod, 2)
1798
1799 # Another warning, no module spec it clears up registry
1800 with clear_and_catch_warnings():
1801 warnings.simplefilter('ignore')
1802 warnings.warn('Another warning')
1803 assert_warn_len_equal(my_mod, 0)
1804
1805
1806@pytest.mark.thread_unsafe(reason="checks global module & deprecated warnings")

Callers

nothing calls this directly

Calls 4

assert_equalFunction · 0.90
_get_fresh_modFunction · 0.85
assert_warn_len_equalFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…