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