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