-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
73 lines (54 loc) · 1.72 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
import tomllib
from pathlib import Path
import pytest
from utils.afc import AFC
from utils.dut import DUT
from utils.rf import RF
def load_config(config_path: str) -> dict:
"""Load configuration from a TOML file."""
config_file = Path(config_path)
if not config_file.exists():
raise FileNotFoundError(f"Can't find config file: {config_path}")
with open(config_file, "rb") as f:
return tomllib.load(f)
def pytest_addoption(parser):
"""Add command line options"""
parser.addoption(
"--config",
action="store",
default="configs/test.toml",
help="Path to the configuration file",
)
@pytest.fixture(scope="session")
def config(request):
"""Global config fixture"""
config_path = request.config.getoption("--config")
return load_config(config_path)
@pytest.fixture
def dut(config):
"""DUT fixture"""
dut_config = config.get("dut", {})
dut = DUT(dut_config)
yield dut
@pytest.fixture
def afc(config):
"""AFC fixture"""
afc_config = config.get("afc", {})
afc = AFC(api_url=afc_config.get("api_url"))
yield afc
@pytest.fixture
def rf(config):
"""RF fixture"""
rf_config = config.get("rf", {})
rf = RF(api_url=rf_config.get("api_url"))
yield rf
def pytest_sessionstart(session):
"""Create environment.properties file at the start of the session."""
config_path = session.config.getoption("--config")
config = load_config(config_path)
with open("./reports/allure-results/environment.properties", "w") as f:
f.write(f"DUT {config['dut']['host']}\n")
f.write(f"AFC {config['afc']['api_url']}\n")
f.write(f"RF {config['rf']['api_url']}\n")
def pytest_runtest_setup(item):
print()