diff --git a/conftest.py b/conftest.py index 285d8b0238..3c566e3672 100644 --- a/conftest.py +++ b/conftest.py @@ -6,6 +6,12 @@ from openpilot.common.prefix import OpenpilotPrefix from openpilot.system.hardware import TICI +def pytest_sessionstart(session): + # TODO: fix tests and enable test order randomization + if session.config.pluginmanager.hasplugin('randomly'): + session.config.option.randomly_reorganize = False + + @pytest.fixture(scope="function", autouse=True) def openpilot_function_fixture(): starting_env = dict(os.environ) diff --git a/poetry.lock b/poetry.lock index 4064417188..da14fcc1eb 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1c6779df1d2ef415664f495c1b06687d06d93588009ca4d1967ad391b58cc1d4 -size 438605 +oid sha256:e7e3be3454e2f4a74667fce67eda6068e5296f9dad824fc2ea8c21566dc77b29 +size 438272 diff --git a/pyproject.toml b/pyproject.toml index 0116cb4c5e..c6a13c4b86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -151,7 +151,7 @@ pytest-subtests = "*" pytest-xdist = "*" pytest-timeout = "*" pytest-timeouts = "*" -pytest-random-order = "*" +pytest-randomly = "*" ruff = "*" scipy = "*" sphinx = "*" diff --git a/selfdrive/car/tests/test_models.py b/selfdrive/car/tests/test_models.py index 0ae104f9f5..aaaa6b9d79 100755 --- a/selfdrive/car/tests/test_models.py +++ b/selfdrive/car/tests/test_models.py @@ -3,6 +3,7 @@ import capnp import os import importlib import pytest +import random import unittest from collections import defaultdict, Counter from typing import List, Optional, Tuple @@ -49,12 +50,10 @@ def get_test_cases() -> List[Tuple[str, Optional[CarTestRoute]]]: with open(os.path.join(BASEDIR, INTERNAL_SEG_LIST), "r") as f: seg_list = f.read().splitlines() - cnt = INTERNAL_SEG_CNT or len(seg_list) - seg_list_iter = iter(seg_list[:cnt]) - - for platform in seg_list_iter: - platform = platform[2:] # get rid of comment - segment_name = SegmentName(next(seg_list_iter)) + seg_list_grouped = [(platform[2:], segment) for platform, segment in zip(seg_list[::2], seg_list[1::2], strict=True)] + seg_list_grouped = random.sample(seg_list_grouped, INTERNAL_SEG_CNT or len(seg_list_grouped)) + for platform, segment in seg_list_grouped: + segment_name = SegmentName(segment) test_cases.append((platform, CarTestRoute(segment_name.route_name.canonical_name, platform, segment=segment_name.segment_num))) return test_cases