Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#15364 closed (fixed)

TestCase files.FileTests failing on Windows

Reported by: mila Owned by: nobody
Component: File uploads/storage Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The reason is that Windows can not delete a file which is open.

I'm attaching a patch which fixes it by closing the opened files.

Before patch:

C:\devel\python\django\tests>runtests.py --settings=test_sqlite files.FileTests
Creating test database for alias 'default'...
Creating test database for alias 'other'...
EE
======================================================================
ERROR: test_files (modeltests.files.tests.FileTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\devel\python\django\tests\modeltests\files\tests.py", line 100, in te
st_files
    obj3.default.delete()
  File "C:\devel\python\django\django\db\models\fields\files.py", line 111, in d
elete
    self.storage.delete(self.name)
  File "C:\devel\python\django\django\core\files\storage.py", line 215, in delet
e
    os.remove(name)
WindowsError: [Error 32] Proces nemß p°Ýstup k souboru, neboŁ jej prßvý vyu×Ývß
jinř proces: u'c:\\docume~1\\milosl~1.poj\\locals~1\\temp\\tmpahds2v\\tests\\def
ault.txt'

======================================================================
ERROR: test_files (modeltests.files.tests.FileTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\devel\python\django\tests\modeltests\files\tests.py", line 16, in tea
rDown
    shutil.rmtree(temp_storage_location)
  File "C:\Program Files\python25\lib\shutil.py", line 169, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Program Files\python25\lib\shutil.py", line 174, in rmtree
    onerror(os.remove, fullname, sys.exc_info())
  File "C:\Program Files\python25\lib\shutil.py", line 172, in rmtree
    os.remove(fullname)
WindowsError: [Error 32] Proces nemß p°Ýstup k souboru, neboŁ jej prßvý vyu×Ývß
jinř proces: 'c:\\docume~1\\milosl~1.poj\\locals~1\\temp\\tmpahds2v\\tests\\defa
ult.txt'

----------------------------------------------------------------------
Ran 1 test in 0.062s

FAILED (errors=2)
Destroying test database for alias 'default'...
Destroying test database for alias 'other'...

After patch:

C:\devel\python\django\tests>runtests.py --settings=test_sqlite files.FileTests
Creating test database for alias 'default'...
Creating test database for alias 'other'...
.
----------------------------------------------------------------------
Ran 1 test in 0.046s

OK
Destroying test database for alias 'default'...
Destroying test database for alias 'other'...

Attachments (1)

FileTests.diff (1.5 KB) - added by mila 4 years ago.

Download all attachments as: .zip

Change History (4)

Changed 4 years ago by mila

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:2 Changed 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

In [15604]:

Fixed #15364 -- Ensure files are closed correctly during file tests. Thanks to Mila for the report and patch.

comment:3 Changed 4 years ago by russellm

In [15608]:

[1.2.X] Fixed #15364 -- Ensure files are closed correctly during file tests. Thanks to Mila for the report and patch.

Backport of r15604 from trunk.

Note: See TracTickets for help on using tickets.
Back to Top