﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
21122	runtests.py fails while trying to clean up temp directory on Windows	Kevin Christopher Henry	Kevin Christopher Henry	"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."	Bug	closed	Testing framework	dev	Normal	fixed	windows	k@…	Accepted	1	0	0	0	0	0
