-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Deleting temporary directories early causes non-unique paths and other issues #10564
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
Comments
im stil of the oppinion that we shoudl always keep by default as for the non-unique names, thats a but caused by using the numbered dirctory helper thats not aware of deletes imho we should return to keeping it all and then revise the filename generator for per test folders |
I am somewhat agnostic to the default value. I can see how that can create a lot of confusion and downstream problems. I do think that the default should be for pytest to clean itself up after success. Eventually.maybe with a more substantial version change. Have you tried to change the pytest behavior by setting up the option provided in the config file. |
I ask this, since I believe that his option should continue to exist for those that depend on global state. |
IMHO keeping it all is the safe default, we clean up deferred after all We clearly demonstrated that the more eager cleanup trigger undesirable issues /details as its using helpers that are not prepared for the new on Filesystem behaviour IMHO we should leave eager cleanup as opt in for data intensive testsuites It my personal impression that most if not all testsuites I'm involved in have better wins by leaving around debug data rather than dropping data early From my pov "Oops the debug data is gone" is a bit of a worse discovery than "I'm so data intensive, i have to opt into early dropping" In addition we missed the accidental logic bomb from make_numbered_dir as before we never dropped early and the main concern was races with other pytest processes, not reuse of the same number in the same process I kinda want to a extraction of the logic from pytest itself at some point |
Given all the information on the thread, I agree it is better to return to the old default. It has been working like that for many years and personally I also had no problems with it. The fact that this might cause headaches for many people once released is a real red flag: we can take the data point that just @The-Compiler already found two hard-to-track problems in his test suite alone. We should be conservative here and keep the old default and possible prevent a myriad of bug report / issues with users. So IMHO we should do two things:
If nobody opposes it, we should create separate issues (linking to this one) and get volunteers to work on them, and close this. |
Agreed on both. Some comments: To do this, we would register this Lines 287 to 290 in cab02e6
However, we should recognize that this has a drawback on testability like I explained here #10545. For example, all of these tests will have to be removed because it won't pass anymore. Lines 95 to 204 in cab02e6
And this is where the PR(#10546) comes in. With the PR, we can register the Of course removing at the end of the session still has more side effects than removing at exit as @The-Compiler is worried. But at the same time, introducing these configurations without having those tests makes it difficult to maintain the feature. |
the remvoe moe should still remove folders, just no longer be the default having a tool for unique folder names will be a separate task that would allow the test to have unique folder names even if preexisting ones where removed |
Yeah it still deletes later, or is there any reason that it should be removed immediately that much? My intension here is that test results should not differ depending on the configuration, so even if we change the default policy to |
@yusuke-kadowaki the problem is that the current numbering tool will reuse folder numbers in case they get deleted the solution is to fix the numbering tool, not to defer the deletion |
Are you saying that deletion needs to be deferred and also the tool needs to be changed? |
No, I'm saying to return to the keep mechanism as default, but also fixing the numbering system to work correctly in case people opt into early delete |
I'm not sure if this is an enough fix after looking at the issue below. IMHO, deferring deletion is universally safer.
|
Are you implying that there should be another configuration to switch between early deletion (when a test finished) vs. late deletion (when pytest finished)? That seems like a lot of complexity and feature creep for something that indeed shouldn't really be a problem. I say we go back to deleting things after the test session (which is orthogonal to deleting vs. keeping directories for passed/failed tests!), and then we don't need to come up with some more complex logic to fix the numbering. |
No, im saying return to the old default, and ensuring that the numbering for per test folders is no longer dependent on the state of the Filesystem for when people switch to early delete |
This is important to consider, because this automatically resolves the numbering issue. Is there a strong, compelling case for deleting folders as soon as the test finishes, as opposed to delay deletion to the end of the test session? |
From my pov anything that won't need immediate deletion won't need deleting at the end of the the process either |
I disagree, deleting at the end of the session frees up disk space, which was one of the driving points for the feature in the first place. For that use case, it doesn't matter if the deletion happens at the end of the test or at the end of the session. |
We should probably get this going anyway by creating those two issues? |
With #10442,
tmp_path
paths are not necessarily unique anymore - in other words, this passed previously, but fails now:This is because those tests used to use unique temp directory names:
but now don't do so anymore, instead, the second test reuses the path the first test did:
In my case, this caused issues with using Qt's QSqlDatabase, which has a list of connections as global state. Since with sqlite, a connection is based on its path, two tests used the same connection name.
I fixed it by closing the database connection properly after the test. This is definitely something I should have done before already.
However, this still violates a basic expectation on how
tmp_path
should behave, which is pointed out in the first sentence of the docs (emphasis mine):It's of course questionable whether the "unique" refers to the directory contents, or the path to it - but as shown above, assuming the latter isn't really something out of the ordinary, especially when passing that path to a library somewhere.
I've also run into another issue with the same commit, which I don't even know how to describe. The gist of it that I had a Qt QFileSystemModel watching the temporary directory for changes - and when it was deleted after the test, Qt/PyQt somehow tried to call a callback lambda on a Python object which was already deleted, thus segfaulting...
This one smells like a PyQt bug, but again demonstrates how files and file paths are inherently attached to some side effects, and deleting them after the test has finished might be too early, depending on what code in the background is doing with it. This also makes me a bit worried about #10546, which I haven't tried yet.
On a more personal note, I also wonder if it's really the right decision to change the default behavior (policy
failed
), even more so in a non-major release. As demonstrated above, it can have very subtle changes on a testsuite.But, perhaps even more important than that, this makes something I consider a great feature of pytest less discoverable. In various places (books, but also my trainings for example) the current behavior of pytest is taught to people, and by the time they discover those files aren't actually kept around anymore, it might already be too late (if e.g. debugging a flaky test). It seems to me that this could lead to much more confusion and frustration compared to it being problematic when storing lots of big files there. The latter seems like a non-issue to me for most cases where I see
tmp_path
being used.@yusuke-kadowaki @nicoddemus @RonnyPfannschmidt @hmaarrfk what do you think?
The text was updated successfully, but these errors were encountered: