Add ignore_errors=True to rmtree

This commit is contained in:
Yusuke Kadowaki 2022-11-03 20:26:53 +09:00
parent c7eb5a3bb8
commit 94740c0336
1 changed files with 6 additions and 3 deletions

View File

@ -273,7 +273,9 @@ def tmp_path(
tmp_path_factory: TempPathFactory = request.session.config._tmp_path_factory # type: ignore tmp_path_factory: TempPathFactory = request.session.config._tmp_path_factory # type: ignore
policy = tmp_path_factory._retention_policy policy = tmp_path_factory._retention_policy
if policy == "failed" and request.node.result_call.passed: if policy == "failed" and request.node.result_call.passed:
rmtree(path) # 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.
rmtree(path, ignore_errors=True)
# remove dead symlink # remove dead symlink
basetemp = tmp_path_factory._basetemp basetemp = tmp_path_factory._basetemp
@ -298,10 +300,11 @@ def pytest_sessionfinish(session, exitstatus: Union[int, ExitCode]):
and policy == "failed" and policy == "failed"
and tmp_path_factory._given_basetemp is None and tmp_path_factory._given_basetemp is None
): ):
# Register to remove the base directory before starting cleanup_numbered_dir
passed_dir = tmp_path_factory._basetemp passed_dir = tmp_path_factory._basetemp
if passed_dir.exists(): if passed_dir.exists():
rmtree(passed_dir) # 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.
rmtree(passed_dir, ignore_errors=True)
@hookimpl(tryfirst=True, hookwrapper=True) @hookimpl(tryfirst=True, hookwrapper=True)