#21122 closed Bug (fixed)
runtests.py fails while trying to clean up temp directory on Windows
Reported by: | Kevin Christopher Henry | Owned by: | Kevin Christopher Henry |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | windows |
Cc: | k@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
There are two unfortunate aspects to this. One is that most test runs end like this:
Traceback (most recent call last): File "runtests.py", line 374, in <module> options.failfast, args) File "runtests.py", line 220, in django_tests teardown(state) File "runtests.py", line 188, in teardown shutil.rmtree(six.text_type(TEMP_DIR)) File "C:\Program Other\Python27\Lib\shutil.py", line 252, in rmtree onerror(os.remove, fullname, sys.exc_info()) File "C:\Program Other\Python27\Lib\shutil.py", line 250, in rmtree os.remove(fullname) WindowsError: [Error 32] The process cannot access the file because it is being used by another process: u'c:\\users\\me\\appdata\\local\\temp\\django_ekeere\\tmprx3hfn'
The other is that the temp directory isn't removed. That's not a severe problem when it comes to temp files and directories, but it's not particularly nice either.
As indicated in the stack trace, the error is caused by the calls to os.remove()
in shutil.rmtree()
in runtests.teardown()
. As indicated in the os.remove()
documentation: "On Windows, attempting to remove a file that is in use causes an exception to be raised." This includes files opened by the current process.
The root cause of this, then, is that a number of tests open temporary files but never close them, thus preventing the cleanup process from working properly.
Change History (6)
comment:1 by , 11 years ago
Cc: | added |
---|---|
Keywords: | windows added |
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Could be related to #19905 - "ResourceWarning in formtools tests".
comment:5 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
I propose a twofold solution:
shutil.rmtree()
and printing a helpful message instead of a panicky stack trace.