-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconftest.py
More file actions
72 lines (54 loc) · 2.09 KB
/
conftest.py
File metadata and controls
72 lines (54 loc) · 2.09 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
66
67
68
69
70
71
72
"""Pytest configuration and fixtures for driver testing."""
import yaml
from pathlib import Path
import pytest
pytest_plugins = ["tests.report_plugin"]
def pytest_addoption(parser):
parser.addoption(
"--port",
action="store",
default=None,
help="Serial port for hardware tests (e.g. /dev/ttyACM0)",
)
parser.addoption(
"--driver",
action="store",
default=None,
help="Run tests for a specific driver only (e.g. hts221)",
)
def pytest_configure(config):
config.addinivalue_line("markers", "mock: tests that run with FakeI2C (no hardware)")
config.addinivalue_line("markers", "hardware: tests that require a real board")
config.addinivalue_line("markers", "manual: tests that require human validation")
config.addinivalue_line("markers", "board: board qualification tests (no driver, hardware only)")
def pytest_collection_modifyitems(config, items):
port = config.getoption("--port")
driver = config.getoption("--driver")
skip_hardware = pytest.mark.skip(reason="needs --port to run hardware tests")
selected = []
for item in items:
# Filter by driver if --driver is specified
if driver and f"[{driver}/" not in item.nodeid:
continue
if "hardware" in item.keywords and not port:
item.add_marker(skip_hardware)
selected.append(item)
items[:] = selected
@pytest.fixture
def port(request):
return request.config.getoption("--port")
def load_scenarios():
"""Load all YAML scenario files from tests/scenarios/."""
scenarios_dir = Path(__file__).parent / "scenarios"
scenarios = []
for yaml_file in sorted(scenarios_dir.glob("*.yaml")):
with open(yaml_file, encoding="utf-8") as f:
scenario = yaml.safe_load(f)
scenario["_file"] = yaml_file.name
scenarios.append(scenario)
return scenarios
@pytest.fixture
def mpremote_bridge(port):
"""Create a MpremoteBridge connected to the board."""
from tests.runner.mpremote_bridge import MpremoteBridge
return MpremoteBridge(port=port)