Skip to content

Commit 4179234

Browse files
Create conftest.py
1 parent 1d64420 commit 4179234

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import importlib.util
2+
import json
3+
import os
4+
import pathlib
5+
import sys
6+
import threading
7+
8+
import pytest
9+
10+
11+
@pytest.fixture(scope='session')
12+
def app_module(tmp_path_factory):
13+
repo_root = pathlib.Path(__file__).resolve().parents[1]
14+
db_dir = tmp_path_factory.mktemp('db')
15+
db_path = db_dir / 'payeeproof_test.db'
16+
17+
os.environ['DB_PATH'] = str(db_path)
18+
os.environ['API_KEYS_JSON'] = json.dumps([
19+
{
20+
'key': 'pp_test_suite_key',
21+
'name': 'ci-suite',
22+
'client_label': 'ci-suite',
23+
'scopes': ['preflight', 'recovery', 'records'],
24+
'webhook_active': False,
25+
}
26+
])
27+
28+
module_name = 'payeeproof_app_under_test'
29+
if module_name in sys.modules:
30+
return sys.modules[module_name]
31+
32+
original_start = threading.Thread.start
33+
threading.Thread.start = lambda self: None
34+
try:
35+
spec = importlib.util.spec_from_file_location(module_name, repo_root / 'app.py')
36+
module = importlib.util.module_from_spec(spec)
37+
sys.modules[module_name] = module
38+
assert spec.loader is not None
39+
spec.loader.exec_module(module)
40+
finally:
41+
threading.Thread.start = original_start
42+
43+
return module
44+
45+
46+
@pytest.fixture()
47+
def client(app_module):
48+
app_module.RATE_LIMIT_BUCKETS.clear()
49+
return app_module.app.test_client()
50+
51+
52+
@pytest.fixture()
53+
def api_headers():
54+
return {'X-API-Key': 'pp_test_suite_key'}

0 commit comments

Comments
 (0)