From fe14ca751f21c2ccd4c22839c15431c6e0abfb2d Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Mon, 23 Oct 2023 20:41:19 -0400 Subject: [PATCH] Pytest: fix local params overriden (#30312) * fix local params being overriden * just reset prefix after completion old-commit-hash: 412f4cbc1a82fe585d2beb5c84032c685f22e5ec --- common/prefix.py | 3 +++ conftest.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/common/prefix.py b/common/prefix.py index 6b7e7e2fd7..c1744e8ff7 100644 --- a/common/prefix.py +++ b/common/prefix.py @@ -14,6 +14,7 @@ class OpenpilotPrefix: self.clean_dirs_on_exit = clean_dirs_on_exit def __enter__(self): + self.original_prefix = os.environ.get('OPENPILOT_PREFIX', None) os.environ['OPENPILOT_PREFIX'] = self.prefix try: os.mkdir(self.msgq_path) @@ -28,6 +29,8 @@ class OpenpilotPrefix: self.clean_dirs() try: del os.environ['OPENPILOT_PREFIX'] + if self.original_prefix is not None: + os.environ['OPENPILOT_PREFIX'] = self.original_prefix except KeyError: pass return False diff --git a/conftest.py b/conftest.py index 2cc906b919..ee46436d3c 100644 --- a/conftest.py +++ b/conftest.py @@ -10,8 +10,13 @@ def openpilot_function_fixture(): # 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)