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