Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest: garbage cannot be removed [Errno 39] #13269

Open
ayushjariyal opened this issue Mar 3, 2025 · 4 comments
Open

pytest: garbage cannot be removed [Errno 39] #13269

ayushjariyal opened this issue Mar 3, 2025 · 4 comments
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity

Comments

@ayushjariyal
Copy link

I am using Python 3.9.20 and pytest 8.3.5. While running pytest, after all tests pass successfully, a long list of warnings appears.

Image

Based on the output, it seems that the rm_rf function is unable to delete some directories because they are not empty.

@RonnyPfannschmidt
Copy link
Member

More context on the failure needed

At first glance this looks incorrect

@ayushjariyal
Copy link
Author

Discription:

  • After running pytest, all tests pass successfully, but a long list of warnings appears. The warnings indicate that rm_rf failed to remove some directories because they are not empty.
  • At first glance, this seems incorrect since pytest should be able to clean up temporary files after test execution.

Expected Behavior:

  • pytest should clean up temporary directories after the tests finish running.
  • No warning should appear unless a legitimate issue prevents deletion.

Actual Behavior:

- pytest fails to remove some directories and raises warnings.

  • The directories are reported as "not empty", even though pytest should handle cleanup.

@The-Compiler
Copy link
Member

Please show some sort of reproducer, nothing we can do with a screenshot and a vague description of an issue which only seems to happen on your end.

@The-Compiler The-Compiler added the status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity label Mar 26, 2025
@nicoddemus
Copy link
Member

Perhaps this might help: pytest already uses shutil.rmtree, which should handle empty directories just fine. It won't work however in a few cases:

  • The current user does not have permission to remove them (it might happen if a test changes permissions for example).
  • A process is keeping an open handle to a file in the temporary directory.

Those are some of the top of my head that could cause this, but there might be others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants