Opened 6 years ago
Closed 5 years ago
#31413 closed Bug (fixed)
migrations.test_loader not isolated on databases that don't support transactions.
| Reported by: | Tim Graham | Owned by: | Hasan Ramezani |
|---|---|---|---|
| Component: | Migrations | Version: | 3.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
On databases that don't support transactions, the changes that each test in migrations.test_loader.LoaderTests makes to the django_migrations table isn't rolled back after each test, resulting in this failure:
======================================================================
FAIL: test_loading_squashed (migrations.test_loader.LoaderTests)
Tests loading a squashed migration
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/tim/code/django/django/test/utils.py", line 373, in inner
return func(*args, **kwargs)
File "/home/tim/code/django/tests/migrations/test_loader.py", line 255, in test_loading_squashed
2,
AssertionError: 1 != 2
For example, to make test_check_consistent_history clean up after itself (this doesn't solve the issue as there are more tests that would need similar changes):
-
tests/migrations/test_loader.py
diff --git a/tests/migrations/test_loader.py b/tests/migrations/test_loader.py index e3a635dc63..2b8f155c72 100644
a b class LoaderTests(TestCase): 415 415 ) 416 416 with self.assertRaisesMessage(InconsistentMigrationHistory, msg): 417 417 loader.check_consistent_history(connection) 418 recorder.record_unapplied('migrations', '0002_second') 418 419 419 420 @override_settings( 420 421 MIGRATION_MODULES={'migrations': 'migrations.test_migrations_squashed_extra'},
There might be a better solution.
Change History (9)
comment:1 by , 6 years ago
| Summary: | LoaderTests not isolated on databases that don't support transactions → migrations.test_loader not isolated on databases that don't support transactions. |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 6 years ago
I ran all migrations tests on a non-transactional database (MyISAM), and a total of 13 tests failed in migrations.test_loader, migrations.test_operations.py, migrations.test_executer.py and migrations.test_commands. Is this behaviour expected?
comment:3 by , 6 years ago
There might be other failures to fix beyond the scope of this ticket. MyISAM isn't tested on CI.
comment:4 by , 6 years ago
The only fix I can think of is manually adding recorder.record_unapplied to all tests which execute recorder.record_applied. Does anyone have a better solution?
comment:5 by , 6 years ago
How about adding a helper method called record_applied that calls recorder.record_applied but also keeps track of the calls so that a tearDown method could call recorder.record_unapplied as needed (and only if transactions aren't supported)?
comment:7 by , 5 years ago
| Has patch: | set |
|---|
comment:8 by , 5 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
I confirmed that two tests in
migrations.test_loaderfail on databases that don't support transactions:====================================================================== FAIL: test_loading_squashed (migrations.test_loader.LoaderTests) Tests loading a squashed migration ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/felixx/repo/django/django/test/utils.py", line 381, in inner return func(*args, **kwargs) File "django/tests/migrations/test_loader.py", line 255, in test_loading_squashed 2, AssertionError: 1 != 2 ====================================================================== FAIL: test_apply (migrations.test_loader.RecorderTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "django/tests/migrations/test_loader.py", line 39, in test_apply set(), AssertionError: Items in the first set but not the second: ('myapp', '0432_ponies')