Skip to content

Commit f499184

Browse files
RonnyPfannschmidtnicoddemusCursor AIclaude
committed
cacheprovider: simplify _make_cachedir cleanup with finally
Use a single finally block instead of duplicating cleanup logic in separate except blocks. The finally block always runs, ensuring cleanup whether the operation succeeds (rename moves dir away, rmtree is no-op), fails with a race condition (ENOTEMPTY/EEXIST), or any other exception. Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com> Co-authored-by: Cursor AI <ai@cursor.sh> Co-authored-by: Anthropic Claude Opus 4.5 <claude@anthropic.com>
1 parent 841fe47 commit f499184

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

src/_pytest/cacheprovider.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,10 @@ def _make_cachedir(target: Path) -> None:
8080
# gets "Directory not empty" from the rename. In this case,
8181
# everything is handled so just continue after cleanup.
8282
# On Windows, the error is a FileExistsError which translates to EEXIST.
83-
shutil.rmtree(path, ignore_errors=True)
8483
if e.errno not in (errno.ENOTEMPTY, errno.EEXIST):
8584
raise
86-
except BaseException:
85+
finally:
8786
shutil.rmtree(path, ignore_errors=True)
88-
raise
8987

9088

9189
@final

0 commit comments

Comments
 (0)