|
|
|
@ -1,3 +1,4 @@ |
|
|
|
|
import contextlib |
|
|
|
|
import gc |
|
|
|
|
import os |
|
|
|
|
import pytest |
|
|
|
@ -25,12 +26,19 @@ def pytest_runtest_call(item): |
|
|
|
|
yield |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="function", autouse=True) |
|
|
|
|
def openpilot_function_fixture(request): |
|
|
|
|
@contextlib.contextmanager |
|
|
|
|
def clean_env(): |
|
|
|
|
starting_env = dict(os.environ) |
|
|
|
|
yield |
|
|
|
|
os.environ.clear() |
|
|
|
|
os.environ.update(starting_env) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="function", autouse=True) |
|
|
|
|
def openpilot_function_fixture(request): |
|
|
|
|
random.seed(0) |
|
|
|
|
|
|
|
|
|
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: |
|
|
|
|
prefix = os.environ["OPENPILOT_PREFIX"] |
|
|
|
@ -40,9 +48,6 @@ def openpilot_function_fixture(request): |
|
|
|
|
# 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) |
|
|
|
|
|
|
|
|
|
# cleanup any started processes |
|
|
|
|
manager.manager_cleanup() |
|
|
|
|
|
|
|
|
@ -55,13 +60,9 @@ def openpilot_function_fixture(request): |
|
|
|
|
# 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) |
|
|
|
|
|
|
|
|
|
with clean_env(): |
|
|
|
|
yield |
|
|
|
|
|
|
|
|
|
os.environ.clear() |
|
|
|
|
os.environ.update(starting_env) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="function") |
|
|
|
|
def tici_setup_fixture(openpilot_function_fixture): |
|
|
|
|