Open jrobichaud opened 1 month ago
The workaround for the moment is to create a custom MigratorTestCase
.
from django_test_migrations.contrib.unittest_case import MigratorTestCase
from django_test_migrations.migrator import Migrator
class ManualMigratorTestCase(MigratorTestCase):
def setUp(self) -> None:
self._migrator = Migrator(self.database_name)
self.old_state = self._migrator.apply_initial_migration(
self.migrate_from,
)
self.prepare()
def migrate(self) -> None:
assert not hasattr(self, "new_state"), "migrate must be called only once"
self.new_state = self._migrator.apply_tested_migration(self.migrate_to)
Maybe we should design a new API instead? We can come up with a better one and deprecate the existing one.
Before using django-test-migrations
, I was using django_migration_testcase and it is how it was working.
django-test-migrations
is much more robust in my opinion but I still miss this behaviour of that library.
The way
MigratorTestCase
is implemented it is only possible to setup test data in theprepare
function which is called duringsetUp
. Because of that there is no way to setup different data for different test functions.In order to be able to support multiple test functions
MigratorTestCase
could be implemented this way:it would allow to add multiple test scenarios like this: