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

Function pytest_sessionfinish

src/_pytest/tmpdir.py:315–340  ·  view source on GitHub ↗

After each session, remove base directory if all the tests passed, the policy is "failed", and the basetemp is not specified by a user.

(session, exitstatus: int | ExitCode)

Source from the content-addressed store, hash-verified

313
314
315def pytest_sessionfinish(session, exitstatus: int | ExitCode):
316 """After each session, remove base directory if all the tests passed,
317 the policy is "failed", and the basetemp is not specified by a user.
318 """
319 tmp_path_factory: TempPathFactory = session.config._tmp_path_factory
320 basetemp = tmp_path_factory._basetemp
321 if basetemp is None:
322 return
323
324 policy = tmp_path_factory._retention_policy
325 if (
326 exitstatus == 0
327 and policy == "failed"
328 and tmp_path_factory._given_basetemp is None
329 ):
330 if basetemp.is_dir():
331 # We do a "best effort" to remove files, but it might not be possible due to some leaked resource,
332 # permissions, etc, in which case we ignore it.
333 rmtree(basetemp, ignore_errors=True)
334
335 # Remove dead symlinks.
336 if basetemp.is_dir():
337 cleanup_dead_symlinks(basetemp)
338
339 # Run the numbered dirs and lock file cleanups registered on the ExitStack.
340 tmp_path_factory._exit_stack.close()
341
342
343@hookimpl(wrapper=True, tryfirst=True)

Callers

nothing calls this directly

Calls 2

cleanup_dead_symlinksFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected