From: Federico Caselli Date: Mon, 15 Apr 2024 19:52:38 +0000 (+0200) Subject: Fix missing pythonpath in test that use subprocess X-Git-Tag: rel_2_0_30~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=354ce373f23f193488d6b73c42fd9b4fa93443a8;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix missing pythonpath in test that use subprocess Ensure the ``PYTHONPATH`` variable is properly initialized when using ``subprocess.run`` in the tests. Fixes: #11268 Change-Id: Ie2db656364931b3be9033dcaaf7a7c56b383ecca (cherry picked from commit b5cf61c504e6ff7cdceeb0ca376eb47a97b9da5a) --- diff --git a/doc/build/changelog/unreleased_20/11268.rst b/doc/build/changelog/unreleased_20/11268.rst new file mode 100644 index 0000000000..40c1eb7bcc --- /dev/null +++ b/doc/build/changelog/unreleased_20/11268.rst @@ -0,0 +1,6 @@ +.. change:: + :tags: bug, test + :tickets: 11268 + + Ensure the ``PYTHONPATH`` variable is properly initialized when + using ``subprocess.run`` in the tests. diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py index 350e954221..2fd16d46db 100644 --- a/test/sql/test_resultset.py +++ b/test/sql/test_resultset.py @@ -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)