File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 11from typing import Optional
22
3+ from django .conf import settings
34from django .core .management import call_command
45from django .core .management .color import no_style
56from django .db import DEFAULT_DB_ALIAS , connections
@@ -73,7 +74,24 @@ def reset(self) -> None:
7374 https://github.com/wemake-services/django-test-migrations/issues/128
7475
7576 """
76- call_command ('migrate' , verbosity = 0 , database = self ._database )
77+ class DisableMigrations :
78+ def __contains__ (self , item : str ) -> bool :
79+ return True
80+
81+ def __getitem__ (self , item : str ) -> None :
82+ return None
83+
84+ pre_migration_modules = settings .MIGRATION_MODULES
85+ try :
86+ settings .MIGRATION_MODULES = DisableMigrations ()
87+ call_command (
88+ 'migrate' ,
89+ verbosity = 0 ,
90+ database = self ._database ,
91+ run_syncdb = True ,
92+ )
93+ finally :
94+ settings .MIGRATION_MODULES = pre_migration_modules
7795
7896 def _migrate (
7997 self ,
Original file line number Diff line number Diff line change @@ -26,3 +26,16 @@ def test_migrator_list(transactional_db):
2626 assert isinstance (old_state , ProjectState )
2727 assert isinstance (new_state , ProjectState )
2828 assert migrator .reset () is None
29+
30+
31+ @pytest .mark .django_db ()
32+ def test_migrator_reset (transactional_db , mocker ):
33+ """Ensure reset does not execute any migrations."""
34+ migrator = Migrator ()
35+ old_state = migrator .apply_initial_migration ([('main_app' , None )])
36+ new_state = migrator .apply_tested_migration ([('main_app' , '0001_initial' )])
37+
38+ run_python_mock = mocker .patch ('django.db.migrations.RunPython' )
39+ migrator .reset ()
40+
41+ assert not run_python_mock .called
You can’t perform that action at this time.
0 commit comments