MCPcopy Create free account
hub / github.com/python/cpython / check_no_warnings

Function check_no_warnings

Lib/test/support/warnings_helper.py:121–142  ·  view source on GitHub ↗

Context manager to check that no warnings are emitted. This context manager enables a given warning within its scope and checks that no warnings are emitted even with that warning enabled. If force_gc is True, a garbage collection is attempted before checking for warnings. This

(testcase, message='', category=Warning, force_gc=False)

Source from the content-addressed store, hash-verified

119
120@contextlib.contextmanager
121def check_no_warnings(testcase, message='', category=Warning, force_gc=False):
122 """Context manager to check that no warnings are emitted.
123
124 This context manager enables a given warning within its scope
125 and checks that no warnings are emitted even with that warning
126 enabled.
127
128 If force_gc is True, a garbage collection is attempted before checking
129 for warnings. This may help to catch warnings emitted when objects
130 are deleted, such as ResourceWarning.
131
132 Other keyword arguments are passed to warnings.filterwarnings().
133 """
134 from test.support import gc_collect
135 with warnings.catch_warnings(record=True) as warns:
136 warnings.filterwarnings('always',
137 message=message,
138 category=category)
139 yield
140 if force_gc:
141 gc_collect()
142 testcase.assertEqual(warns, [])
143
144
145@contextlib.contextmanager

Callers 1

Calls 2

gc_collectFunction · 0.90
assertEqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…