cleanup environment variables between tests (#30167)

This commit is contained in:
Justin Newberry 2023-10-04 11:51:44 -07:00 committed by GitHub
parent 2048808827
commit 786f13b0e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 1 deletions

View File

@ -1,10 +1,28 @@
import os
import pytest
from openpilot.common.prefix import OpenpilotPrefix
@pytest.fixture(scope="function", autouse=True)
def global_setup_and_teardown():
def openpilot_function_fixture():
starting_env = dict(os.environ)
# setup a clean environment for each test
with OpenpilotPrefix():
yield
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)