Fish Trophy

chipx86 got a fish trophy!

Fix a model contamination issue with TestModelsLoaderMixin.

Review Request #9229 — Created Sept. 28, 2017 and submitted


A recent unit test was affected by a bug in TestModelsLoaderMixin
causing a models module to remain in Django's cache after the test suite
concluded. This only happened if a subclass defined a tests app that
already contained a file. If it didn't define a specific
tests app or didn't include a, then the cleanup would work
correctly, but if both were present then it would fail.

The reason for this inconsistency is that if a valid didn't
exist, we'd create one and store a reference to it, which allowed us to
later remove it from the module cache. If one already existed, then
there wouldn't be a reference, so it never got removed.

The logic for this is now a bit more careful to explicitly check for a
models module and to store it. If we can't import, we then proceed to
create a module and store that. This ensures we always have a module to
work with and to clean up at the end, fixing all tests.

All unit tests pass. Before this change, some failed with unknown app
errors involving models from prior test suites.

  1. Ship It!
  1. Ship It!
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-0.10.x (96c5e82)