Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#11032 closed (fixed)

Failed regressiontest on Windows for ImageField

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

Description

On Windows (Vista32), the file_storage test fails if PIL is installed (if PIL is not installed, this test is not executed):

======================================================================
FAIL: Doctest: regressiontests.file_storage.models.__test__.API_TESTS
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\edc\django-trunk\django\test\_doctest.py", line 2180, in runTest
AssertionError: Failed doctest test for regressiontests.file_storage.models.__test__.API_TESTS
  File "C:\edc\django_src\tests\regressiontests\file_storage\models.py", line unknown line number, in API_TESTS

----------------------------------------------------------------------
File "C:\edc\django_src\tests\regressiontests\file_storage\models.py", line ?, in regressiontests.file_storage.models.__test__.API_TESTS
Failed example:
    shutil.rmtree(temp_storage_dir)
Exception raised:
    Traceback (most recent call last):
      File "C:\edc\django-trunk\django\test\_doctest.py", line 1267, in __run
      File "<doctest regressiontests.file_storage.models.__test__.API_TESTS[26]>", line 1, in <module>
        shutil.rmtree(temp_storage_dir)
      File "C:\Program Files\Python 2.5\Lib\shutil.py", line 169, in rmtree
        rmtree(fullname, ignore_errors, onerror)
      File "C:\Program Files\Python 2.5\Lib\shutil.py", line 174, in rmtree
        onerror(os.remove, fullname, sys.exc_info())
      File "C:\Program Files\Python 2.5\Lib\shutil.py", line 172, in rmtree
        os.remove(fullname)
    WindowsError: [Error 32] The process cannot access the file because it is being used by another
    process: 'c:\\users\\joeri\\appdata\\local\\temp\\tmp34vz8s\\tests\\mug'


----------------------------------------------------------------------
Ran 4 tests in 1.116s

FAILED (failures=1)

When cleaning up at the end of the test (tests/regressiontests/file_storage/models.py), shutil.rmtree has problems with p.mugshot._file still being opened by a process. The quickfix is to add >>> p.mugshot.close() just _before_ the last line of the test: >>> shutil.rmtree(temp_storage_dir).

It's a perk of shutil on Windows (other platforms seem to don't care and just remove the file anyway) that exposes this but the actual cause might be deeper. The file (p.mugshot._file) is left open (or even reopened despite the dimension_cache...) by calling p.mugshot.width and/or p.mugshot.height. Removing the lines below from the test also "removes" the problem:

>>> p.mugshot.width
16
>>> p.mugshot.height
16

Attachments (1)

11032.diff (494 bytes) - added by bthomas 6 years ago.
Close file in last regression test

Download all attachments as: .zip

Change History (10)

comment:1 Changed 6 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

See #8817

comment:2 Changed 6 years ago by joeri

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

Cool. Must have missed that one for the 1.1 milestone.

comment:3 Changed 6 years ago by joeri

  • Resolution duplicate deleted
  • Status changed from closed to reopened

Maybe I marked it as duplicate too soon. Applying the final patch (8817-final.patch) in #8817 still leads to the same failed test. However, the deeper cause I mentioned in the description is addressed in that ticket.

comment:4 Changed 6 years ago by bthomas

The file_storage tests fail for me on Windows as well, but for a different reason. "shot" is being held open, not "mug". If I remove the last test:

# Make sure that wrapping the file in a file still works
>>> p3.mugshot.file.open()
>>> p = Person.objects.create(name="Bob The Builder", mugshot=File(p3.mugshot.file))
>>> p.save()

everything is fine. If instead I just add p3.mugshot.file.close() after the p.save(), the test will also pass.

comment:5 Changed 6 years ago by bthomas

I probably should mention that I'm running the latest trunk, so I have the patch for #8817.

Changed 6 years ago by bthomas

Close file in last regression test

comment:6 Changed 6 years ago by bthomas

  • Has patch set

Attached a trivial patch for the latest trunk that allows the file_storage tests to pass on Windows.

comment:7 Changed 6 years ago by kmtracey

  • milestone set to 1.1
  • Triage Stage changed from Unreviewed to Ready for checkin

I'd guess r10737 is what fixed 'mug' being left open, as it wasn't previously (yesterday) fixed by the fix for #8817. What remains looks like a straightforward test bug of opening a file without closing it.

comment:8 Changed 6 years ago by kmtracey

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

(In [10741]) Fixed #11032: close() a file explictly open()'d in a test, so that deleting the file tree it is in doesn't fail on Windows. Thanks bthomas for the patch.

comment:9 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

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