From b5cf61c504e6ff7cdceeb0ca376eb47a97b9da5a Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Mon, 15 Apr 2024 21:52:38 +0200 Subject: [PATCH] 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 --- doc/build/changelog/unreleased_20/11268.rst | 6 ++++++ test/sql/test_resultset.py | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 doc/build/changelog/unreleased_20/11268.rst 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 938df1ac3a..e6d02da7e9 100644 --- a/test/sql/test_resultset.py +++ b/test/sql/test_resultset.py @@ -530,8 +530,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) -- 2.47.2