Opened 3 years ago

Closed 3 years ago

#18754 closed Bug (fixed)

staticfiles test failure under Windows

Reported by: kmtracey Owned by: kmtracey
Component: contrib.staticfiles Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Recording this in a ticket to explain the code change.

C:\Users\kmtracey\django\git-django\tests> --settings=test_sqlite staticfiles_tests.TestCollectionCachedStorage.test_template_tag_return staticfiles_tests.TestCollectionSimpleCachedStorage.test_template_tag_return
Creating test database for alias 'default'...
Creating test database for alias 'other'...
FAIL: test_template_tag_return (regressiontests.staticfiles_tests.tests.TestCollectionSimpleCachedStorage)
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\git-django\tests\regressiontests\staticfiles_tests\", line 560, in test_template_tag_return
  File "C:\Users\kmtracey\django\git-django\tests\regressiontests\staticfiles_tests\", line 101, in assertStaticRenders
    self.assertEqual(self.render_template(template, **kwargs), result)
AssertionError: u'/static/test/file.dad0999e4f8f.txt' != u'/static/test/file.deploy12345.txt'
- /static/test/file.dad0999e4f8f.txt
?                    ------  ^^^
+ /static/test/file.deploy12345.txt
?                     +++++++ ^

Ran 2 tests in 1.036s

FAILED (failures=1)
Destroying test database for alias 'default'...
Destroying test database for alias 'other'...

Both tests test the static rendering of static file "test/file.txt"

The 2nd test is finding something put in the cache by the first test.

During test setUp, where collectstatic is being called, CachedFilesMixin post_process is setting up the cache keys for found files by:

# and then set the cache accordingly
hashed_paths[self.cache_key(name)] = hashed_name

here name has backslashes on Windows. Later during the first test run the name looked for has forward slashes, the cache key generated is different than what was put in the cache by setUp, cache misses, and a value is set in the cache for the key value generated with the forward slash version of the name. The cache is not cleared between tests and the 2nd call to setUp again sets up the cache using the names with backslashes, but then when the 2nd test looks up the name with forward slashes it finds the value previously set by the 1st test.

Fix is to replace backslashes with forward slashes in the name used for key generation in post_process. I think. If not someone with a better grasp of this code feel free to step in with the real fix.

Change History (1)

comment:1 Changed 3 years ago by Karen Tracey <kmtracey@…>

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

In [b82eb10b2605477b3e583c9378257a9e6c8fd2ed]:

Fixed #18754 -- cache keys created by post_process

Corrected to always generate the cache keys from file names with
forward slashes, not backslashes.

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