Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
import os
import pytest

from openpilot.common.prefix import OpenpilotPrefix
from openpilot.system.manager import manager
from openpilot.system.hardware import TICI, HARDWARE

# TODO: pytest-cpp doesn't support FAIL, and we need to create test translations in sessionstart
# pending https://github.com/pytest-dev/pytest-cpp/pull/147
collect_ignore = [
Expand Down Expand Up @@ -47,6 +43,10 @@ def clean_env():

@pytest.fixture(scope="function", autouse=True)
def openpilot_function_fixture(request):
# Lazy import to speed up test collection
from openpilot.common.prefix import OpenpilotPrefix
from openpilot.system.manager import manager

with clean_env():
# setup a clean environment for each test
with OpenpilotPrefix(shared_download_cache=request.node.get_closest_marker("shared_download_cache") is not None) as prefix:
Expand Down Expand Up @@ -76,19 +76,35 @@ def openpilot_class_fixture():
@pytest.fixture(scope="function")
def tici_setup_fixture(request, openpilot_function_fixture):
"""Ensure a consistent state for tests on-device. Needs the openpilot function fixture to run first."""
# Lazy import to speed up test collection
from openpilot.system.hardware import HARDWARE

if 'skip_tici_setup' in request.keywords:
return
HARDWARE.initialize_hardware()
HARDWARE.set_power_save(False)
os.system("pkill -9 -f athena")


# Cache for TICI value to avoid repeated imports during collection
_tici_cache = None


def _is_tici():
"""Lazy check for TICI to speed up collection. Uses file check instead of heavy import."""
global _tici_cache
if _tici_cache is None:
# TICI is True if /TICI file exists - avoid importing hardware module
_tici_cache = os.path.isfile('/TICI')
return _tici_cache


@pytest.hookimpl(tryfirst=True)
def pytest_collection_modifyitems(config, items):
skipper = pytest.mark.skip(reason="Skipping tici test on PC")
for item in items:
if "tici" in item.keywords:
if not TICI:
if not _is_tici():
item.add_marker(skipper)
else:
item.fixturenames.append('tici_setup_fixture')
Expand Down
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ allow-direct-references = true

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "--ignore=openpilot/ --ignore=opendbc/ --ignore=panda/ --ignore=rednose_repo/ --ignore=tinygrad_repo/ --ignore=teleoprtc_repo/ --ignore=msgq/ -Werror --strict-config --strict-markers --durations=10 -n auto --dist=loadgroup"
addopts = "-Werror --strict-config --strict-markers --durations=10 -n auto --dist=loadgroup"
cpp_files = "test_*"
cpp_harness = "selfdrive/test/cpp_harness.py"
python_files = "test_*.py"
Expand Down Expand Up @@ -172,6 +172,16 @@ testpaths = [
"tools/cabana",
"cereal/messaging/tests",
]
# Use norecursedirs instead of --ignore flags for faster collection
norecursedirs = [
"openpilot",
"opendbc",
"panda",
"rednose_repo",
"tinygrad_repo",
"teleoprtc_repo",
"msgq",
]

[tool.codespell]
quiet-level = 3
Expand Down