flag to cleanup generated tmp_path objects
See original GitHub issueWhen using the tmp_path factory, the path remains until:
- The system is restarted
- The number of tmp_path objects is greater than the limit (currently 3)
- a basepath is given (This will just overwrite the existing basepath, but will not provide any cleanup).
I propose a flag that cleans up tmp_path
objects on completion of the test.
Usage would look like
python -m pytest --autocleanup
This would execute the following steps:
- create a list of each
tmp_path
object created. - execute code
- iterate through the list deleting each tmp_path that was created (if it still exists)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
tempfile — Generate temporary files and directories — Python ...
Return a file-like object that can be used as a temporary storage area. ... O_TMPFILE flag is used if it is available and...
Read more >[testing] automatically clean up temp dirs during teardown #6471
Write a custom context manager that takes a hard-coded path and a flag to clean up or not to make it easy to...
Read more >How do I automatically delete temp files in C#? - Stack Overflow
You could P/Invoke CreateFile and pass the FILE_FLAG_DELETE_ON_CLOSE flag. ... Delete(tempFileToDelete); } } } // Clean up using (File.
Read more >How to use temporary directories and files in tests - Pytest
You can use the tmp_path fixture which will provide a temporary directory unique to the test invocation, created in the base temporary directory....
Read more >ansible-runner Documentation - Read the Docs
Ansible Runner is a tool and python library that helps when interfacing with Ansible directly or as part of another.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@asottile’s suggestion is on point, and in fact you might even overwrite the builtin fixture into your root
conftest.py
:I’m closing because I believe this should be enough to fix OP’s problem without changing anything in pytest.
@kjaymiller feel free to follow up with further questions though.
May we know the surrounding use case that makes the current auto cleanup misfit?
The folders intentionally stay around to do post mortem analysis