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