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
Some tests leak temporary files #81602
Comments
When running tests, the tempoary directory is not left clean: there are temporary files which are not removed. I wrote a PoC change to detect such bugs and I found that at least test_shutil and test_urllib leak such temporary files/directories. |
Test leaking a temporary file in test_urllib: I'm not sure of my fix: diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index f6ce9cb6d5..fdddd6e2d8 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -283,6 +283,7 @@ def urlretrieve(url, filename=None, reporthook=None, data=None):
reporthook(blocknum, bs, size)
if size >= 0 and read < size:
+ urlcleanup()
raise ContentTooShortError(
"retrieval incomplete: got only %i out of %i bytes"
% (read, size), result) |
Using PR 14415, the following test of test_multiprocessing_spawn emits a false alarm because multiprocessing use "Finalizer" objects which are only finalized "later": Workaround, call explicitly _run_finalizers(): diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index eef262d723..bfecbab9ee 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -5651,6 +5651,7 @@ def install_tests_in_module_dict(remote_globs, start_method):
if need_sleep:
time.sleep(0.5)
multiprocessing.process._cleanup()
+ multiprocessing.util._run_finalizers()
test.support.gc_collect()
remote_globs['setUpModule'] = setUpModule |
About urllib.request, I created: bpo-37475 "What is urllib.request.urlcleanup() function?". |
./python -u -m test test_multiprocessing_spawn -R 3:3 still fail: ERROR: test_context (test.test_multiprocessing_spawn.TestStartMethod) PR 14601 fix these tests when test_multiprocessing_spawn is run more than once. |
I created a follow-up issue: bpo-37507 "multiprocessing: Add a stop() method to ForkServer". |
It seems like tests don't leak temporary files anymore: $ mkdir ~/TEMP
$ TMPDIR=~/TEMP TEMPDIR=~/TEMP ./python -m test -v -r -u all,-gui
$ ls ~/TEMP
# empty directory I close the issue. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: