-
Notifications
You must be signed in to change notification settings - Fork 115
/
conftest.py
81 lines (65 loc) · 2.13 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
import logging
import os
import sys
from datetime import datetime
from typing import List, Optional
import pytest
from pytest_embedded.plugin import multi_dut_fixture
def pytest_configure(config):
target = config.getoption("--target")
if "stm32" in target:
config.option.embedded_services = "serial"
elif "raspberry" in target:
pass
elif "pi_pico" in target:
config.option.embedded_services = "serial"
else:
config.option.embedded_services = "esp,idf"
def pytest_collection_modifyitems(
session: pytest.Session, config: pytest.Config, items: List[pytest.Item]
):
"""Modify test collection based on selected target"""
target = config.getoption("--target")
# Filter the test cases
filtered_items = []
for item in items:
# filter by target
all_markers = [marker.name for marker in item.iter_markers()]
if target not in all_markers:
continue
filtered_items.append(item)
items[:] = filtered_items
@pytest.fixture(scope="session", autouse=True)
def session_tempdir() -> str:
_tmpdir = os.path.join(
os.path.dirname(__file__),
"pytest_embedded_log",
datetime.now().strftime("%Y-%m-%d_%H-%M-%S"),
)
os.makedirs(_tmpdir, exist_ok=True)
return _tmpdir
@pytest.fixture
@multi_dut_fixture
def build_dir(
request: pytest.FixtureRequest, app_path: str, target: Optional[str]
) -> str:
"""
Check local build dir and return the valid one
Returns:
valid build directory
"""
check_dirs = []
build_folder = os.getenv("CI_BUILD_FOLDER")
if build_folder is not None:
check_dirs.append(build_folder)
check_dirs.append("build")
for check_dir in check_dirs:
binary_path = os.path.join(app_path, check_dir)
if os.path.isdir(binary_path):
logging.info(f"find valid binary path: {binary_path}")
return check_dir
logging.warning(
"checking binary path: %s... missing... try another place", binary_path
)
logging.error("no build dir valid. Please build the binary and run pytest again.")
sys.exit(1)