Update tmpdir.py

This commit is contained in:
Bruno Oliveira 2023-04-14 12:35:58 -03:00 committed by GitHub
parent 2d01dbd07a
commit ae6eac77bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 5 deletions

View File

@ -299,20 +299,19 @@ def pytest_sessionfinish(session, exitstatus: Union[int, ExitCode]):
if basetemp is None: if basetemp is None:
return return
# Remove dead symlinks.
cleanup_dead_symlinks(basetemp)
policy = tmp_path_factory._retention_policy policy = tmp_path_factory._retention_policy
if ( if (
exitstatus == 0 exitstatus == 0
and policy == "failed" and policy == "failed"
and tmp_path_factory._given_basetemp is None and tmp_path_factory._given_basetemp is None
): ):
passed_dir = basetemp if basetemp.exists():
if passed_dir.exists():
# We do a "best effort" to remove files, but it might not be possible due to some leaked resource, # We do a "best effort" to remove files, but it might not be possible due to some leaked resource,
# permissions, etc, in which case we ignore it. # permissions, etc, in which case we ignore it.
rmtree(passed_dir, ignore_errors=True) rmtree(passed_dir, ignore_errors=True)
# Remove dead symlinks.
cleanup_dead_symlinks(basetemp)
@hookimpl(tryfirst=True, hookwrapper=True) @hookimpl(tryfirst=True, hookwrapper=True)