rdobuilder 74698f
From b88042cfb32866a00d39b678bb224eb55ecf53c1 Mon Sep 17 00:00:00 2001
rdobuilder 74698f
From: Lumir Balhar <lbalhar@redhat.com>
rdobuilder 74698f
Date: Tue, 22 Jun 2021 22:10:17 +0200
rdobuilder 74698f
Subject: [PATCH] Preserve any existing PYTHONPATH in tests
rdobuilder 74698f
rdobuilder 74698f
---
rdobuilder 74698f
 tests/conftest.py | 10 ++++++++--
rdobuilder 74698f
 1 file changed, 8 insertions(+), 2 deletions(-)
rdobuilder 74698f
rdobuilder 74698f
diff --git a/tests/conftest.py b/tests/conftest.py
rdobuilder 74698f
index 4ad1ff23..7200d286 100644
rdobuilder 74698f
--- a/tests/conftest.py
rdobuilder 74698f
+++ b/tests/conftest.py
rdobuilder 74698f
@@ -118,9 +118,15 @@ def dev_server(xprocess, request, tmp_path):
rdobuilder 74698f
         class Starter(ProcessStarter):
rdobuilder 74698f
             args = [sys.executable, run_path, name, json.dumps(kwargs)]
rdobuilder 74698f
             # Extend the existing env, otherwise Windows and CI fails.
rdobuilder 74698f
-            # Modules will be imported from tmp_path for the reloader.
rdobuilder 74698f
+            # Modules will be imported from tmp_path for the reloader
rdobuilder 74698f
+            # but any existing PYTHONPATH is preserved.
rdobuilder 74698f
             # Unbuffered output so the logs update immediately.
rdobuilder 74698f
-            env = {**os.environ, "PYTHONPATH": str(tmp_path), "PYTHONUNBUFFERED": "1"}
rdobuilder 74698f
+            original_python_path = os.getenv("PYTHONPATH")
rdobuilder 74698f
+            if original_python_path:
rdobuilder 74698f
+                new_python_path = os.pathsep.join((original_python_path, str(tmp_path)))
rdobuilder 74698f
+            else:
rdobuilder 74698f
+                new_python_path = str(tmp_path)
rdobuilder 74698f
+            env = {**os.environ, "PYTHONPATH": new_python_path, "PYTHONUNBUFFERED": "1"}
rdobuilder 74698f
 
rdobuilder 74698f
             @cached_property
rdobuilder 74698f
             def pattern(self):
rdobuilder 74698f
-- 
rdobuilder 74698f
2.31.1
rdobuilder 74698f