-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconftest.py
97 lines (74 loc) · 2.73 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from os import path
import httpretty
import pandas as pd
import pytest
import yaml
from tests.api.handlers._base import (PARSED_TESTS_DIR, REQUESTS_TESTS_DIR,
RESPONSES_TESTS_DIR)
REQUESTS_FP = list(REQUESTS_TESTS_DIR.glob('*.yml'))
RESPONSES_FP = list(RESPONSES_TESTS_DIR.glob('*.yml'))
PARSED_YML_FP = list(PARSED_TESTS_DIR.glob('*.yml'))
PARSED_DF_FP = list(PARSED_TESTS_DIR.glob('*.parquet.gzip'))
def pytest_addoption(parser):
parser.addoption('--run-slow',
action='store_true',
default=False,
help='run slow tests.')
parser.addoption(
'--run-private',
action='store_true',
default=False,
help='run tests across methods which are not publicly exposed.')
def pytest_configure(config):
config.addinivalue_line('markers', 'slow: mark test as slow to run')
config.addinivalue_line('markers',
'private: mark test as not publicly exposed')
def pytest_collection_modifyitems(config, items):
skips = set(['slow', 'private'])
if config.getoption('--run-slow'):
# --run-slow given in cli: do not skip slow tests
skips.remove('slow')
if config.getoption('--run-private'):
# --run-private given in cli: do not skip private tests
skips.remove('private')
if not skips:
return
skip_slow = pytest.mark.skip(reason='need --run-slow option to run')
skip_private = pytest.mark.skip(reason='need --run-private option to run')
for item in items:
if 'slow' in item.keywords and 'slow' in skips:
item.add_marker(skip_slow)
if 'private' in item.keywords and 'private' in skips:
item.add_marker(skip_private)
@pytest.fixture(scope="session")
def read_responses():
resps = dict()
for f in RESPONSES_FP:
name = path.basename(str(f)).split('.')[0].split('_')[-1]
with open(f, 'r') as f_yml:
data = yaml.safe_load(f_yml)
resps[name] = data
yield resps
@pytest.fixture(scope="session")
def read_parsed_yml():
parsed = dict()
for f in PARSED_YML_FP:
name = path.basename(str(f)).split('.')[0].split('_')[-1]
with open(f, 'r') as f_yml:
data = yaml.safe_load(f_yml)
parsed[name] = data
yield parsed
@pytest.fixture(scope="session")
def read_parsed_df():
parsed = dict()
for f in PARSED_DF_FP:
name = path.basename(str(f)).split('.')[0].split('_')[-1]
data = pd.read_parquet(f)
parsed[name] = data
yield parsed
@pytest.fixture(scope="session")
def mock_socket():
httpretty.enable(verbose=True, allow_net_connect=False)
yield True
httpretty.disable()
httpretty.reset()