@@ -620,6 +620,49 @@ def test_makemigrations_handle_merge(self):
620620 self .assertIn ("Branch 0002_conflicting_second" , output )
621621 self .assertIn ("Created new merge migration" , output )
622622
623+ def test_makemigration_merge_dry_run (self ):
624+ """
625+ Makes sure that makemigrations respects --dry-run option when fixing
626+ migration conflicts (#24427).
627+ """
628+ out = six .StringIO ()
629+ with self .temporary_migration_module (module = "migrations.test_migrations_conflict" ) as migration_dir :
630+ call_command ("makemigrations" , "migrations" , dry_run = True , merge = True , interactive = False , stdout = out )
631+ merge_file = os .path .join (migration_dir , '0003_merge.py' )
632+ self .assertFalse (os .path .exists (merge_file ))
633+ output = force_text (out .getvalue ())
634+ self .assertIn ("Merging migrations" , output )
635+ self .assertIn ("Branch 0002_second" , output )
636+ self .assertIn ("Branch 0002_conflicting_second" , output )
637+ self .assertNotIn ("Created new merge migration" , output )
638+
639+ def test_makemigration_merge_dry_run_verbosity_3 (self ):
640+ """
641+ Makes sure that `makemigrations --merge --dry-run` writes the merge
642+ migration file to stdout with `verbosity == 3` (#24427).
643+ """
644+ out = six .StringIO ()
645+ with self .temporary_migration_module (module = "migrations.test_migrations_conflict" ) as migration_dir :
646+ call_command ("makemigrations" , "migrations" , dry_run = True , merge = True , interactive = False ,
647+ stdout = out , verbosity = 3 )
648+ merge_file = os .path .join (migration_dir , '0003_merge.py' )
649+ self .assertFalse (os .path .exists (merge_file ))
650+ output = force_text (out .getvalue ())
651+ self .assertIn ("Merging migrations" , output )
652+ self .assertIn ("Branch 0002_second" , output )
653+ self .assertIn ("Branch 0002_conflicting_second" , output )
654+ self .assertNotIn ("Created new merge migration" , output )
655+
656+ # Additional output caused by verbosity 3
657+ # The complete merge migration file that would be written
658+ self .assertIn ("# -*- coding: utf-8 -*-" , output )
659+ self .assertIn ("class Migration(migrations.Migration):" , output )
660+ self .assertIn ("dependencies = [" , output )
661+ self .assertIn ("('migrations', '0002_second')" , output )
662+ self .assertIn ("('migrations', '0002_conflicting_second')" , output )
663+ self .assertIn ("operations = [" , output )
664+ self .assertIn ("]" , output )
665+
623666 def test_makemigrations_dry_run (self ):
624667 """
625668 Ticket #22676 -- `makemigrations --dry-run` should not ask for defaults.
0 commit comments