MCPcopy Index your code
hub / github.com/python/cpython / test_atexit_with_low_memory

Method test_atexit_with_low_memory

Lib/test/test_atexit.py:197–223  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

195 # _PyRefchain_Trace() on memory allocation error.
196 @unittest.skipIf(support.Py_TRACE_REFS, 'cannot test Py_TRACE_REFS build')
197 def test_atexit_with_low_memory(self):
198 # gh-140080: Test that setting low memory after registering an atexit
199 # callback doesn't cause an infinite loop during finalization.
200 code = textwrap.dedent("""
201 import atexit
202 import _testcapi
203
204 def callback():
205 print("hello")
206
207 atexit.register(callback)
208 # Simulate low memory condition
209 _testcapi.set_nomemory(0)
210 """)
211
212 with os_helper.temp_dir() as temp_dir:
213 script = script_helper.make_script(temp_dir, 'test_atexit_script', code)
214 with SuppressCrashReport():
215 with script_helper.spawn_python(script,
216 stderr=subprocess.PIPE) as proc:
217 proc.wait()
218 stdout = proc.stdout.read()
219 stderr = proc.stderr.read()
220
221 self.assertIn(proc.returncode, (0, 1))
222 self.assertNotIn(b"hello", stdout)
223 self.assertIn(b"MemoryError", stderr)
224
225
226if __name__ == "__main__":

Callers

nothing calls this directly

Calls 8

SuppressCrashReportClass · 0.90
temp_dirMethod · 0.80
assertInMethod · 0.80
assertNotInMethod · 0.80
dedentMethod · 0.45
make_scriptMethod · 0.45
waitMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected