Skip to content

Commit d9b3790

Browse files
committed
updated tests to match gmt changes; added per test cleanup from gmt to example directories as well
1 parent 48d6d7b commit d9b3790

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

test/conftest.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,38 @@
1+
import os
2+
import sys
3+
import pytest
4+
5+
current_dir = os.path.dirname(os.path.abspath(__file__))
6+
sys.path.append(f"{current_dir}/../../green-metrics-tool/lib")
7+
8+
## VERY IMPORTANT to override the config file here
9+
## otherwise it will automatically connect to non-test DB and delete all your real data
10+
from global_config import GlobalConfig
11+
from db import DB
12+
GlobalConfig().override_config(config_name='test-config.yml')
13+
114
def pytest_addoption(parser):
215
parser.addoption("--name", action="store", default="stress")
316

4-
517
def pytest_generate_tests(metafunc):
618
# This is called for every test. Only get/set command line arguments
719
# if the argument is specified in the list of test "fixturenames".
820
option_value = metafunc.config.option.name
921
if 'name' in metafunc.fixturenames and option_value is not None:
10-
metafunc.parametrize("name", [option_value])
22+
metafunc.parametrize("name", [option_value])
23+
24+
# should we hardcode test-db here?
25+
@pytest.fixture(autouse=True)
26+
def cleanup_after_test():
27+
yield
28+
tables = DB().fetch_all("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'")
29+
for table in tables:
30+
table_name = table[0]
31+
DB().query(f'TRUNCATE TABLE "{table_name}" RESTART IDENTITY CASCADE')
32+
33+
### If you wish to turn off the above auto-cleanup per test, include the following in your
34+
### test module:
35+
# from conftest import cleanup_after_test
36+
# @pytest.fixture(autouse=False) # Set autouse to False to override the fixture
37+
# def cleanup_after_test():
38+
# pass

test/smoke_test.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,10 @@ def example_directories():
3535
return example_dirs
3636

3737
def run_test_on_directory(directory, capsys, skip_unsafe=False):
38-
project_name = f"test_{utils.randomword(12)}"
39-
40-
# Insert Project into testing DB
41-
project_id = DB().fetch_one('INSERT INTO "projects" ("name","uri","email","last_run","created_at") \
42-
VALUES \
43-
(%s,%s,\'manual\',NULL,NOW()) RETURNING id;', params=(project_name, directory))[0]
38+
name = f"test_{utils.randomword(12)}"
4439

4540
# Run the application
46-
runner = Runner(uri=directory, uri_type="folder", pid=project_id, skip_unsafe=skip_unsafe, skip_system_checks=True)
41+
runner = Runner(name=name, uri=directory, uri_type="folder", dev_repeat_run=True, skip_unsafe=skip_unsafe, skip_system_checks=True)
4742
runner.run()
4843

4944
# Capture Std.Out and Std.Err and make Assertions

0 commit comments

Comments
 (0)