MCPcopy
hub / github.com/pytest-dev/pytest / cleanup

Function cleanup

src/_pytest/unraisableexception.py:86–104  ·  src/_pytest/unraisableexception.py::cleanup
(
    *, config: Config, prev_hook: Callable[[sys.UnraisableHookArgs], object]
)

Source from the content-addressed store, hash-verified

84
85
86def cleanup(
87 *, config: Config, prev_hook: Callable[[sys.UnraisableHookArgs], object]
88) -> None:
89 class="cm"># On PyPy, objects (e.g. coroutines) can survive GC rounds because executing
90 class="cm"># their __del__ can resurrect them. The Trio project determined experimentally
91 class="cm"># that 5 passes are needed on PyPy to flush everything. On CPython, reference
92 class="cm"># counting handles most cleanup immediately, so 1 pass is sufficient.
93 _default_gc_collect_iterations = 5 if sys.implementation.name == class="st">"pypy" else 1
94 gc_collect_iterations = config.stash.get(
95 gc_collect_iterations_key, _default_gc_collect_iterations
96 )
97 try:
98 try:
99 gc_collect_harder(gc_collect_iterations)
100 collect_unraisable(config)
101 finally:
102 sys.unraisablehook = prev_hook
103 finally:
104 del config.stash[unraisable_exceptions]
105
106
107def unraisable_hook(

Callers

nothing calls this directly

Calls 3

gc_collect_harderFunction · 0.85
collect_unraisableFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected