1111## otherwise it will automatically connect to non-test DB and delete all your real data
1212from lib .global_config import GlobalConfig
1313from lib .db import DB
14+ from tests import test_functions as Tests
15+
1416GlobalConfig ().override_config (config_location = f"{ GMT_TEST_DIR } /test-config.yml" )
1517
1618def pytest_addoption (parser ):
@@ -23,18 +25,19 @@ def pytest_generate_tests(metafunc):
2325 if 'name' in metafunc .fixturenames and option_value is not None :
2426 metafunc .parametrize ("name" , [option_value ])
2527
26- # should we hardcode test-db here?
28+ # Note: This fixture runs always
29+ # Pytest collects all fixtures before running any tests
30+ # no matter which order they are loaded in
2731@pytest .fixture (autouse = True )
28- def cleanup_after_test ():
32+ def setup_and_cleanup_test ():
33+ GlobalConfig ().override_config (config_location = f"{ GMT_TEST_DIR } /test-config.yml" )
2934 yield
30- tables = DB ().fetch_all ("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_type != 'VIEW'" )
31- for table in tables :
32- table_name = table [0 ]
33- DB ().query (f'TRUNCATE TABLE "{ table_name } " RESTART IDENTITY CASCADE' )
35+ Tests .reset_db ()
36+
3437
3538### If you wish to turn off the above auto-cleanup per test, include the following in your
3639### test module:
37- # from conftest import cleanup_after_test
40+ # from conftest import setup_and_cleanup_test
3841# @pytest.fixture(autouse=False) # Set autouse to False to override the fixture
39- # def cleanup_after_test ():
42+ # def setup_and_cleanup_test ():
4043# pass
0 commit comments