Opened 10 years ago
Last modified 10 years ago
#23640 closed Bug
StaticLiveServerTestCase does not properly respect data migrations — at Initial Version
Reported by: | Ruben Nielsen | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | 1.7 |
Severity: | Normal | Keywords: | data migration, functional tests |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When data migrations exists for a project, it is expected that each test case has these migrations run before running the test.
That is indeed the case for django.tests.TestCase (unit tests), but it is NOT working for django.contrib.staticfiles.testing.StaticLiveServerTestCase (functional tests).
Migrations seem to be run for each class, e.g. MyTestCase(StaticLiveServerTestCase), but not for the methods of this class. That is, if MyTestCase has 3 methods with tests, the migrations are only loaded for the first one, and then the database is wiped, and the objects from the data migration is no longer present for the next two methods.
A minimal reproduction of this issue - along with a guide to the issue and which files to look at - can be found here:
https://github.com/eldamir/django_migration_bug