From 26d822b66184901a2ad34d806d8f0ace0428b272 Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Wed, 4 Oct 2023 11:51:44 -0700 Subject: [PATCH] cleanup environment variables between tests (#30167) old-commit-hash: 786f13b0e308b117dbae0bd40afa43635321991d --- conftest.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/conftest.py b/conftest.py index e139ab8400..2cc906b919 100644 --- a/conftest.py +++ b/conftest.py @@ -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)