Skip to content

Conversation

@graingert
Copy link
Member

@graingert graingert commented Oct 25, 2020

Closes #7940

see also #7933 for my first attempt

@graingert graingert force-pushed the clean-garbage-tmpdirs-with-tempfile-temporary-directory branch from a53c978 to 09b0e20 Compare October 25, 2020 12:01
garbage = parent.joinpath(f"garbage-{uuid.uuid4()}")
path.rename(garbage)
rm_rf(garbage)
with tempfile.TemporaryDirectory(
Copy link
Member

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

Copy link
Member Author

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

@bluetech
Copy link
Member

IIUC, this is basically a hack to coerce TemporaryDirectory.cleanup() to do the dirty work for us, right? I like it :) Although I think a comment is in order to explain what it's doing, it seems odd if you don't get it.

@RonnyPfannschmidt
Copy link
Member

Since the rmtree helper is simple, how about replicating

@graingert
Copy link
Member Author

so it turns out this PR does fix my original issue, but my test case is hitting #7947

@graingert graingert force-pushed the clean-garbage-tmpdirs-with-tempfile-temporary-directory branch from 09b0e20 to 216c7af Compare October 26, 2020 12:51
@graingert
Copy link
Member Author

IIUC, this is basically a hack to coerce TemporaryDirectory.cleanup() to do the dirty work for us, right? I like it :) Although I think a comment is in order to explain what it's doing, it seems odd if you don't get it.

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

@graingert graingert force-pushed the clean-garbage-tmpdirs-with-tempfile-temporary-directory branch 2 times, most recently from 5ba2ca9 to ceea364 Compare October 26, 2020 13:08
@graingert
Copy link
Member Author

this breaks on windows and I don't know why

Base automatically changed from master to main March 9, 2021 20:40
@RonnyPfannschmidt
Copy link
Member

@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

@RonnyPfannschmidt
Copy link
Member

@bluetech bluetech force-pushed the clean-garbage-tmpdirs-with-tempfile-temporary-directory branch from d3407fe to 3d4a8b1 Compare October 7, 2025 20:25
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 7, 2025
@bluetech
Copy link
Member

bluetech commented Oct 7, 2025

I rebased to fix a conflict.

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
@bluetech bluetech force-pushed the clean-garbage-tmpdirs-with-tempfile-temporary-directory branch from 3d4a8b1 to f78b56a Compare October 7, 2025 20:27
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.

Pytest cannot delete tmp_path directories without stat.S_IXUSR mode bit set

3 participants