]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix missing pythonpath in test that use subprocess
authorFederico Caselli <cfederico87@gmail.com>
Mon, 15 Apr 2024 19:52:38 +0000 (21:52 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Mon, 15 Apr 2024 19:53:10 +0000 (21:53 +0200)
Ensure the ``PYTHONPATH`` variable is properly initialized when
using ``subprocess.run`` in the tests.

Fixes: #11268
Change-Id: Ie2db656364931b3be9033dcaaf7a7c56b383ecca
(cherry picked from commit b5cf61c504e6ff7cdceeb0ca376eb47a97b9da5a)

doc/build/changelog/unreleased_20/11268.rst [new file with mode: 0644]
test/sql/test_resultset.py

diff --git a/doc/build/changelog/unreleased_20/11268.rst b/doc/build/changelog/unreleased_20/11268.rst
new file mode 100644 (file)
index 0000000..40c1eb7
--- /dev/null
@@ -0,0 +1,6 @@
+.. change::
+    :tags: bug, test
+    :tickets: 11268
+
+    Ensure the ``PYTHONPATH`` variable is properly initialized when
+    using ``subprocess.run`` in the tests.
index 350e95422147677b9d473a8c89434c109e1b9ef8..2fd16d46db066a8455aa752f2f632b1e64375b0c 100644 (file)
@@ -528,8 +528,14 @@ class CursorResultTest(fixtures.TablesTest):
             "import sqlalchemy; import pickle; print(["
             f"r[0] for r in pickle.load(open('''{name}''', 'rb'))])"
         )
+        parts = list(sys.path)
+        if os.environ.get("PYTHONPATH"):
+            parts.append(os.environ["PYTHONPATH"])
+        pythonpath = os.pathsep.join(parts)
         proc = subprocess.run(
-            [sys.executable, "-c", code], stdout=subprocess.PIPE
+            [sys.executable, "-c", code],
+            stdout=subprocess.PIPE,
+            env={**os.environ, "PYTHONPATH": pythonpath},
         )
         exp = str([r[0] for r in result]).encode()
         eq_(proc.returncode, 0)