[Django] #21122: runtests.py fails while trying to clean up temp directory on Windows

5 views
Skip to first unread message

Django

unread,
Sep 18, 2013, 9:02:51 PM9/18/13
to django-...@googlegroups.com
#21122: runtests.py fails while trying to clean up temp directory on Windows
-----------------------------------+--------------------
Reporter: marfire | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------
There are two unfortunate aspects to this. One is that most test runs end
like this:

{{{
#!python
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/21122>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 18, 2013, 9:03:58 PM9/18/13
to django-...@googlegroups.com
#21122: runtests.py fails while trying to clean up temp directory on Windows
-----------------------------------+--------------------------------------
Reporter: marfire | Owner: marfire
Type: Bug | Status: assigned

Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: windows | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by marfire):

* status: new => assigned
* cc: k@… (added)
* needs_better_patch: => 0
* needs_tests: => 0
* keywords: => windows
* owner: nobody => marfire
* needs_docs: => 0


Comment:

I propose a twofold solution:

1. Tracking down the tests that are not closing their open temp files, and
making sure they close them.

2. Catching exceptions generated by `shutil.rmtree()` and printing a
helpful message instead of a panicky stack trace.

--
Ticket URL: <https://code.djangoproject.com/ticket/21122#comment:1>

Django

unread,
Sep 19, 2013, 7:34:13 AM9/19/13
to django-...@googlegroups.com
#21122: runtests.py fails while trying to clean up temp directory on Windows
-----------------------------------+------------------------------------

Reporter: marfire | Owner: marfire
Type: Bug | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: windows | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by timo):

* stage: Unreviewed => Accepted


Comment:

Could be related to #19905 - "ResourceWarning in formtools tests".

--
Ticket URL: <https://code.djangoproject.com/ticket/21122#comment:2>

Django

unread,
Sep 19, 2013, 4:58:09 PM9/19/13
to django-...@googlegroups.com
#21122: runtests.py fails while trying to clean up temp directory on Windows
-----------------------------------+------------------------------------
Reporter: marfire | Owner: marfire
Type: Bug | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: windows | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by marfire):

I couldn't reproduce the other ticket but I added a note there.

--
Ticket URL: <https://code.djangoproject.com/ticket/21122#comment:3>

Django

unread,
Sep 19, 2013, 7:17:34 PM9/19/13
to django-...@googlegroups.com
#21122: runtests.py fails while trying to clean up temp directory on Windows
-----------------------------------+------------------------------------
Reporter: marfire | Owner: marfire
Type: Bug | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: windows | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by marfire):

* has_patch: 0 => 1


Comment:

See https://github.com/django/django/pull/1649.

--
Ticket URL: <https://code.djangoproject.com/ticket/21122#comment:4>

Django

unread,
Oct 2, 2013, 9:13:15 AM10/2/13
to django-...@googlegroups.com
#21122: runtests.py fails while trying to clean up temp directory on Windows
-----------------------------------+------------------------------------
Reporter: marfire | Owner: marfire
Type: Bug | Status: closed

Component: Testing framework | Version: master
Severity: Normal | Resolution: fixed

Keywords: windows | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"978e1351a60a0d7b44d367877784109ac01ebc62"]:
{{{
#!CommitTicketReference repository=""
revision="978e1351a60a0d7b44d367877784109ac01ebc62"
Fixed #21122 -- Improved clean up of test temp directory on Windows

- Fixed test that didn't close the files it opened
- Caught and handled exception when temp directory cannot be removed
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21122#comment:5>

Django

unread,
Oct 2, 2013, 7:20:37 PM10/2/13
to django-...@googlegroups.com
#21122: runtests.py fails while trying to clean up temp directory on Windows
-----------------------------------+------------------------------------
Reporter: marfire | Owner: marfire
Type: Bug | Status: closed
Component: Testing framework | Version: master
Severity: Normal | Resolution: fixed
Keywords: windows | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"02c7dbd2559de4fa09cf6c644a2434e440230c0d"]:
{{{
#!CommitTicketReference repository=""
revision="02c7dbd2559de4fa09cf6c644a2434e440230c0d"
[1.6.x] Fixed #21122 -- Improved clean up of test temp directory on
Windows

- Fixed test that didn't close the files it opened
- Caught and handled exception when temp directory cannot be removed

Backport of 978e1351a6 of master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21122#comment:6>

Reply all
Reply to author
Forward
0 new messages