mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-19 06:33:57 +08:00
* randomize internal seg list segments * random * pytest-randomly sets random.seed to a consistent value for all the workers/processes * noeol * update * Revert "update" This reverts commit aff9a69c4e5e3934deebaa33986b42f44b55b002. * lock * don't randomize by default * remove random-order * strict * random * one fix * test * does nothing * rm tests * Revert "rm tests" This reverts commit b548e3fcd48e60538695506888d863c01b459d27. * (can't repro locally) just athena should be fine * bs1 * bs2 * bs3 * bs4 * bs5 * wrong way * no controls * no car * no board * controls? * crazy -common * Revert "crazy -common" This reverts commit 02365d712b3d09cab1893cce2261a4b418bb3851. * test athena * test athena 2 * test athena 3 * test athena 4 * test athena 5 * test athena 6 * test athena 7 * test athena 8 * test athena 9 * ?? * in one commit * common? * car and board * -controls -board * random-order * no board * revert * car/tests * least likely * try * try 2 * draft * draft * so much better * cmt * use randomly * not needed here * directly modify option works * bb * test time * Revert "test time" This reverts commit 2c5caabe2b470b47b7322e37800680b92773fccc. * tmut * i concur * revert
65 lines
1.8 KiB
Python
65 lines
1.8 KiB
Python
import os
|
|
import pytest
|
|
import random
|
|
|
|
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)
|
|
|
|
random.seed(0)
|
|
|
|
# setup a clean environment for each test
|
|
with OpenpilotPrefix():
|
|
prefix = os.environ["OPENPILOT_PREFIX"]
|
|
|
|
yield
|
|
|
|
# ensure the test doesn't change the prefix
|
|
assert "OPENPILOT_PREFIX" in os.environ and prefix == os.environ["OPENPILOT_PREFIX"]
|
|
|
|
os.environ.clear()
|
|
os.environ.update(starting_env)
|
|
|
|
|
|
# If you use setUpClass, the environment variables won't be cleared properly,
|
|
# so we need to hook both the function and class pytest fixtures
|
|
@pytest.fixture(scope="class", autouse=True)
|
|
def openpilot_class_fixture():
|
|
starting_env = dict(os.environ)
|
|
|
|
yield
|
|
|
|
os.environ.clear()
|
|
os.environ.update(starting_env)
|
|
|
|
|
|
@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 not TICI and "tici" in item.keywords:
|
|
item.add_marker(skipper)
|
|
|
|
if "xdist_group_class_property" in item.keywords:
|
|
class_property_name = item.get_closest_marker('xdist_group_class_property').args[0]
|
|
class_property_value = getattr(item.cls, class_property_name)
|
|
item.add_marker(pytest.mark.xdist_group(class_property_value))
|
|
|
|
|
|
@pytest.hookimpl(trylast=True)
|
|
def pytest_configure(config):
|
|
config_line = (
|
|
"xdist_group_class_property: group tests by a property of the class that contains them"
|
|
)
|
|
config.addinivalue_line("markers", config_line)
|