forked from soxoj/maigret
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
71 lines (47 loc) · 1.7 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import glob
import logging
import os
import pytest
from _pytest.mark import Mark
from maigret.sites import MaigretDatabase
from maigret.maigret import setup_arguments_parser
from maigret.settings import Settings
CUR_PATH = os.path.dirname(os.path.realpath(__file__))
JSON_FILE = os.path.join(CUR_PATH, '../maigret/resources/data.json')
SETTINGS_FILE = os.path.join(CUR_PATH, '../maigret/resources/settings.json')
TEST_JSON_FILE = os.path.join(CUR_PATH, 'db.json')
LOCAL_TEST_JSON_FILE = os.path.join(CUR_PATH, 'local.json')
empty_mark = Mark('', (), {})
def by_slow_marker(item):
return item.get_closest_marker('slow', default=empty_mark)
def pytest_collection_modifyitems(items):
items.sort(key=by_slow_marker, reverse=False)
def get_test_reports_filenames():
return glob.glob(os.path.join('report_*'), recursive=False)
def remove_test_reports():
reports_list = get_test_reports_filenames()
for f in reports_list:
os.remove(f)
logging.error(f'Removed test reports {reports_list}')
@pytest.fixture(scope='session')
def default_db():
return MaigretDatabase().load_from_file(JSON_FILE)
@pytest.fixture(scope='function')
def test_db():
return MaigretDatabase().load_from_file(TEST_JSON_FILE)
@pytest.fixture(scope='function')
def local_test_db():
return MaigretDatabase().load_from_file(LOCAL_TEST_JSON_FILE)
@pytest.fixture(autouse=True)
def reports_autoclean():
remove_test_reports()
yield
remove_test_reports()
@pytest.fixture(scope='session')
def argparser():
settings = Settings()
settings.load([SETTINGS_FILE])
return setup_arguments_parser(settings)
@pytest.fixture(scope="session")
def httpserver_listen_address():
return ("localhost", 8989)