Visitar URL original
Fix cleanup of empty directories with read-only parents by 2Zest · Pull Request #15360 · pytest-dev/pytest · GitHub
Skip to content

Fix cleanup of empty directories with read-only parents - #15360

Open
2Zest wants to merge 1 commit into
pytest-dev:mainfrom
2Zest:fix/rm-rf-readonly-empty-dir-15341
Open

2Zest wants to merge 1 commit into
pytest-dev:mainfrom
2Zest:fix/rm-rf-readonly-empty-dir-15341

Conversation

@2Zest

@2Zest 2Zest commented Nov 9, 2026

Copy link
Copy Markdown

Summary

When pytest removes a session directory containing an empty directory whose parent is read-only, the os.rmdir retry can fail again because only the leaf was made writable. That error is swallowed by the numbered-directory cleanup, leaving the entire session tree as a garbage-* directory. Restore permissions on parent directories before retrying, and keep a stubborn entry from aborting the rest of the removal.

Testing

  • PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python -m pytest testing/test_tmpdir.py -q (57 passed, 12 skipped)
  • python -m ruff check src/_pytest/pathlib.py testing/test_tmpdir.py
  • git diff --check

Fixes #15341

Co-authored-by: Codex <noreply@openai.com>
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 9, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rm_rf: empty directory under a read-only parent aborts removal; whole session basetemp left as garbage-*

1 participant