-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
65 lines (48 loc) · 1.96 KB
/
conftest.py
File metadata and controls
65 lines (48 loc) · 1.96 KB
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
import pytest
import json
import os
import logging
from pps.utils.configuration import ConfBorg
# py.test tweaking
# in this exemple: initialize configuration borg for the whole test session
def pytest_report_header(config):
""" return a string in test report header """
return "Hey this are the tests"
def pytest_addoption(parser):
"""create a confpath command line arg for py.test"""
parser.addoption('--confpath', action="append", default=[], help="configuration full path")
@pytest.fixture(scope="function")
def carriagereturn(request):
""" will be run for each test function see pytest.ini """
print(" ")
@pytest.fixture(scope="session")
def initloggers(request):
""" will be run for each test session see pytest.ini """
# initialize basic loggers
print("****** INIT LOGGERS ******")
logging.basicConfig(level=logging.DEBUG)
@pytest.fixture(scope="session")
def confborg(request):
"""
- allow confborg to be a valid test parameter,
this code will be executed before the test code
once per session
"""
def run_only_at_session_end():
print("\n ********** End of test session **********")
request.addfinalizer(run_only_at_session_end)
print("********** Test session init **********")
if pytest.config.getoption('confpath') is not None:
print("Launch test with conf:", pytest.config.getoption('confpath', default=None))
conf_path = pytest.config.getoption('confpath')
# previously returns a list, get the string
if len(pytest.config.getoption('confpath')) > 0:
conf_path = pytest.config.getoption('confpath')[0]
if os.path.exists(conf_path):
with open(conf_path, 'rt') as f:
conf = json.load(f)
# add data path which is calculated at run time
conf['data_path'] = os.path.dirname(os.path.dirname(conf_path))
conf['data_path'] = os.path.join(conf['data_path'], 'data')
res = ConfBorg(conf)
return res