|
28 | 28 | from .pathlib import make_numbered_dir |
29 | 29 | from .pathlib import make_numbered_dir_with_cleanup |
30 | 30 | from .pathlib import rm_rf |
31 | | -from .pathlib import cleanup_dead_symlink |
| 31 | +from .pathlib import cleanup_dead_symlinks |
32 | 32 | from _pytest.compat import final, get_user_id |
33 | 33 | from _pytest.config import Config |
34 | 34 | from _pytest.config import ExitCode |
@@ -289,31 +289,30 @@ def tmp_path( |
289 | 289 |
|
290 | 290 | del request.node.stash[tmppath_result_key] |
291 | 291 |
|
292 | | - # remove dead symlink |
293 | | - basetemp = tmp_path_factory._basetemp |
294 | | - if basetemp is None: |
295 | | - return |
296 | | - cleanup_dead_symlink(basetemp) |
297 | | - |
298 | 292 |
|
299 | 293 | def pytest_sessionfinish(session, exitstatus: Union[int, ExitCode]): |
300 | 294 | """After each session, remove base directory if all the tests passed, |
301 | 295 | the policy is "failed", and the basetemp is not specified by a user. |
302 | 296 | """ |
303 | 297 | tmp_path_factory: TempPathFactory = session.config._tmp_path_factory |
304 | | - if tmp_path_factory._basetemp is None: |
| 298 | + basetemp = tmp_path_factory._basetemp |
| 299 | + if basetemp is None: |
305 | 300 | return |
| 301 | + |
306 | 302 | policy = tmp_path_factory._retention_policy |
307 | 303 | if ( |
308 | 304 | exitstatus == 0 |
309 | 305 | and policy == "failed" |
310 | 306 | and tmp_path_factory._given_basetemp is None |
311 | 307 | ): |
312 | | - passed_dir = tmp_path_factory._basetemp |
313 | | - if passed_dir.exists(): |
| 308 | + if basetemp.is_dir(): |
314 | 309 | # We do a "best effort" to remove files, but it might not be possible due to some leaked resource, |
315 | 310 | # permissions, etc, in which case we ignore it. |
316 | | - rmtree(passed_dir, ignore_errors=True) |
| 311 | + rmtree(basetemp, ignore_errors=True) |
| 312 | + |
| 313 | + # Remove dead symlinks. |
| 314 | + if basetemp.is_dir(): |
| 315 | + cleanup_dead_symlinks(basetemp) |
317 | 316 |
|
318 | 317 |
|
319 | 318 | @hookimpl(tryfirst=True, hookwrapper=True) |
|
0 commit comments