]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Assert scratch directory is cleaned up after class teardown
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 30 Nov 2019 17:09:34 +0000 (12:09 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 30 Nov 2019 17:09:34 +0000 (12:09 -0500)
Some race conditions are occurring due to the NormPath test
and overall there should be no scratch directories remaining
when tests are complete.

Change-Id: I848b39c4ca473f424a76247abfa4071074808e9d

alembic/testing/env.py
alembic/testing/plugin/plugin_base.py
tests/test_script_production.py

index 01e78f8564aa579da3dd30b7f9e35be4043e1a57..15f777720c882e409b7c0cbc0678f0a75ef09c7e 100644 (file)
@@ -27,9 +27,12 @@ def staging_env(create=True, template="generic", sourceless=False):
 
     cfg = _testing_config()
     if create:
+
         path = os.path.join(_get_staging_directory(), "scripts")
-        if os.path.exists(path):
-            shutil.rmtree(path)
+        assert not os.path.exists(path), (
+            "staging directory %s already exists; poor cleanup?" % path
+        )
+
         command.init(cfg, path, template=template)
         if sourceless:
             try:
index dc31c580b8ed2c8d8f5b9e3cb596f4a0fecd5d14..953528235262c3f2b9b382554e9c1dbfa6cf3eb9 100644 (file)
@@ -11,6 +11,7 @@ import sys
 
 from sqlalchemy.testing.plugin.plugin_base import *  # noqa
 from sqlalchemy.testing.plugin.plugin_base import post
+from sqlalchemy.testing.plugin.plugin_base import stop_test_class as sqla_stc
 
 py3k = sys.version_info >= (3, 0)
 
@@ -24,6 +25,16 @@ else:
 
 
 # override selected SQLAlchemy pytest hooks with vendored functionality
+def stop_test_class(cls):
+    sqla_stc(cls)
+    import os
+    from alembic.testing.env import _get_staging_directory
+
+    assert not os.path.exists(_get_staging_directory()), (
+        "staging directory %s was not cleaned up" % _get_staging_directory()
+    )
+
+
 def want_class(name, cls):
     from sqlalchemy.testing import config
     from sqlalchemy.testing import fixtures
index 4c1bec1dd5d9aadc6ae0324517fea2fadc5d376d..ae2a2b85ca2bc22ac01cd6430286a89f798321af 100644 (file)
@@ -1261,6 +1261,9 @@ class NormPathTest(TestBase):
     def setUp(self):
         self.env = staging_env()
 
+    def tearDown(self):
+        clear_staging_env()
+
     def test_script_location(self):
         config = _no_sql_testing_config()