From: Mike Bayer Date: Sat, 30 Nov 2019 17:09:34 +0000 (-0500) Subject: Assert scratch directory is cleaned up after class teardown X-Git-Tag: rel_1_3_2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12cc251e446d386bc5bbefe98cfdfd416f2c50ee;p=thirdparty%2Fsqlalchemy%2Falembic.git Assert scratch directory is cleaned up after class teardown 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 --- diff --git a/alembic/testing/env.py b/alembic/testing/env.py index 01e78f85..15f77772 100644 --- a/alembic/testing/env.py +++ b/alembic/testing/env.py @@ -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: diff --git a/alembic/testing/plugin/plugin_base.py b/alembic/testing/plugin/plugin_base.py index dc31c580..95352823 100644 --- a/alembic/testing/plugin/plugin_base.py +++ b/alembic/testing/plugin/plugin_base.py @@ -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 diff --git a/tests/test_script_production.py b/tests/test_script_production.py index 4c1bec1d..ae2a2b85 100644 --- a/tests/test_script_production.py +++ b/tests/test_script_production.py @@ -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()