MCPcopy Index your code
hub / github.com/RustPython/RustPython / warnings_state

Function warnings_state

Lib/test/test_warnings/__init__.py:36–63  ·  view source on GitHub ↗

Use a specific warnings implementation in warning_tests.

(module)

Source from the content-addressed store, hash-verified

34
35@contextmanager
36def warnings_state(module):
37 """Use a specific warnings implementation in warning_tests."""
38 global __warningregistry__
39 for to_clear in (sys, warning_tests):
40 try:
41 to_clear.__warningregistry__.clear()
42 except AttributeError:
43 pass
44 try:
45 __warningregistry__.clear()
46 except NameError:
47 pass
48 original_warnings = warning_tests.warnings
49 if module._use_context:
50 saved_context, context = module._new_context()
51 else:
52 original_filters = module.filters
53 module.filters = original_filters[:]
54 try:
55 module.simplefilter("once")
56 warning_tests.warnings = module
57 yield
58 finally:
59 warning_tests.warnings = original_warnings
60 if module._use_context:
61 module._set_context(saved_context)
62 else:
63 module.filters = original_filters
64
65
66class TestWarning(Warning):

Calls 1

clearMethod · 0.45

Tested by 6

test_filenameMethod · 0.68
test_stacklevelMethod · 0.68