2023-10-05 02:51:44 +08:00
|
|
|
import os
|
2023-09-06 09:52:40 +08:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from openpilot.common.prefix import OpenpilotPrefix
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="function", autouse=True)
|
2023-10-05 02:51:44 +08:00
|
|
|
def openpilot_function_fixture():
|
|
|
|
starting_env = dict(os.environ)
|
|
|
|
|
2023-09-06 09:52:40 +08:00
|
|
|
# setup a clean environment for each test
|
|
|
|
with OpenpilotPrefix():
|
|
|
|
yield
|
2023-10-05 02:51:44 +08:00
|
|
|
|
|
|
|
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)
|