11
11
## otherwise it will automatically connect to non-test DB and delete all your real data
12
12
from lib .global_config import GlobalConfig
13
13
from lib .db import DB
14
+ from tests import test_functions as Tests
15
+
14
16
GlobalConfig ().override_config (config_location = f"{ GMT_TEST_DIR } /test-config.yml" )
15
17
16
18
def pytest_addoption (parser ):
@@ -23,18 +25,19 @@ def pytest_generate_tests(metafunc):
23
25
if 'name' in metafunc .fixturenames and option_value is not None :
24
26
metafunc .parametrize ("name" , [option_value ])
25
27
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
27
31
@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" )
29
34
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
+
34
37
35
38
### If you wish to turn off the above auto-cleanup per test, include the following in your
36
39
### test module:
37
- # from conftest import cleanup_after_test
40
+ # from conftest import setup_and_cleanup_test
38
41
# @pytest.fixture(autouse=False) # Set autouse to False to override the fixture
39
- # def cleanup_after_test ():
42
+ # def setup_and_cleanup_test ():
40
43
# pass
0 commit comments