@@ -311,6 +311,8 @@ def _assert_lines(self, revs):
311311 eq_ (lines , set (revs ))
312312
313313 def test_doesnt_create_alembic_version (self ):
314+ with self .bind .begin () as conn :
315+ conn .exec_driver_sql ("drop table if exists alembic_version" )
314316 command .current (self .cfg )
315317 engine = self .bind
316318 with engine .connect () as conn :
@@ -345,6 +347,40 @@ def test_heads_upg(self):
345347 with self ._assert_lines (["a2" , "b3" ]):
346348 command .current (self .cfg )
347349
350+ def test_check_heads_success (self ):
351+ """
352+ "--check-heads" succeeds if all head revisions are applied.
353+ """
354+ command .stamp (self .cfg , ())
355+ command .stamp (self .cfg , (self .a3 .revision , self .b3 .revision ))
356+ with self ._assert_lines (["a3" , "b3" ]):
357+ command .current (self .cfg , check_heads = True )
358+
359+ @testing .combinations (
360+ ["a2" ],
361+ ["a3" ],
362+ ["b3" ],
363+ ["a2" , "b3" ],
364+ ["a3" , "b2" ],
365+ argnames = "revs" ,
366+ )
367+ def test_check_heads_fail (self , revs ):
368+ """
369+ "--check-heads" succeeds if all head revisions are applied.
370+ """
371+ command .stamp (self .cfg , ())
372+ command .stamp (
373+ self .cfg , tuple (getattr (self , rev ).revision for rev in revs )
374+ )
375+ assert_raises_message (
376+ util .DatabaseNotAtHead ,
377+ "Database is not on all head revisions" ,
378+ command .current ,
379+ self .cfg ,
380+ check_heads = True ,
381+ )
382+ command .stamp (self .cfg , ())
383+
348384
349385class RevisionTest (TestBase ):
350386 def setUp (self ):
@@ -1562,7 +1598,7 @@ def existing_pyproject_fixture(self):
15621598 yield config .Config (
15631599 self .cfg .config_file_name , toml_file = root / "pyproject.toml"
15641600 )
1565- shutil . rmtree (root )
1601+ os . unlink (root / "pyproject.toml" )
15661602
15671603 @testing .variation ("cmd" , ["list_templates" , "init" ])
15681604 def test_init_custom_template_location (self , cmd , custom_template_fixture ):
0 commit comments