Fix leaky tests
While working on !1639 (merged), @schneider-y ran into issues with a leaky test that mocked the S3 URL generation but never released it. The test module is arkindex.images.tests.test_thumbnail
. Django runs tests in alphabetical order, and this test module is the last to care about S3 URLs. When running the tests in reverse with manage.py test --reverse
or in a random order with manage.py test --shuffle
, some tests can fail because of this leaky test as well as other issues.
I noticed that some SQL query counts were incorrect when running in reverse because the ContentType cache was not always cleared, due to missing calls to super()
in overriden setup or teardown methods and due to the cache clear being called after a test is finished and not before a test starts: the first test of each class might have run without the cache being cleared.
There is still one test that is affected by the test order: the assertExactQueries
on move_element
has two INSERT
queries to insert a few ElementPaths. The order of the paths within each query is different each time because Django uses a set()
and not anything that preserves an ordering.