-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Clean garbage tmpdirs with tempfile.TemporaryDirectory #7941
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
base: main
Are you sure you want to change the base?
Clean garbage tmpdirs with tempfile.TemporaryDirectory #7941
Conversation
a53c978
to
09b0e20
Compare
src/_pytest/pathlib.py
Outdated
garbage = parent.joinpath(f"garbage-{uuid.uuid4()}") | ||
path.rename(garbage) | ||
rm_rf(garbage) | ||
with tempfile.TemporaryDirectory( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should spec a root directory and a prefix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dir is the root directory
IIUC, this is basically a hack to coerce |
Since the rmtree helper is simple, how about replicating |
so it turns out this PR does fix my original issue, but my test case is hitting #7947 |
09b0e20
to
216c7af
Compare
I'm just composing a comment for this now - and I'd like to comment the use of the rename to "garbage-", but I'm not really clear on why this rename was done originally: https://github.com/pytest-dev/pytest/pull/3988/files#diff-b2559484fd51ba4a312585ab8375eda68c43b0b66bb329ec036106255928a2b9R169 |
216c7af
to
5ba2ca9
Compare
Python has a very nice rm_rf hidden in tempfile.TemporaryDirectory._rmtree we can use it to cleanup our "garbage-" dir https://github.com/python/cpython/blob/3d43f1dce3e9aaded38f9a2c73e3c66acf85505c/Lib/tempfile.py#L784-L812
5ba2ca9
to
ceea364
Compare
this breaks on windows and I don't know why |
@graingert the name garbage was replicated from pylib which uses it as indicator of folder names that can be removed even if things fail from the processs that initially tries to take them out |
for more information, see https://pre-commit.ci
Closes #7940
see also #7933 for my first attempt