iotests: tolerate being run outside of pyvenv
Modify the iotests environment preparation so that it can detect when it is being run outside of the configure-time virtual environment and give a warning to the user, suggesting the use of the meson run script instead. As a bonus, since the test executor itself does not actually rely on anything in the configure-time venv in and of itself, it is possible to just modify the python executable it uses for launching tests to be the correct, configured venv that has access to qemu.qmp and other test dependencies. Reviewed-by: Thomas Huth <thuth@redhat.com> Tested-by: Thomas Huth <thuth@redhat.com> Message-ID: <20260218213416.674483-9-jsnow@redhat.com> Signed-off-by: John Snow <jsnow@redhat.com>
John Snow committed
Feb 18, 2026 at 16:34 UTC
0e0bf74cddc65db27aca400671f147b7f33d8db4
1 file changed
+24
-1
tests/qemu-iotests/testenv.py
+24
-1
@@ -20,6 +20,7 @@ import os
20
import sys
21
import tempfile
22
from pathlib import Path
23
+import shlex
24
import shutil
25
import collections
26
import contextlib
@@ -140,7 +141,29 @@ class TestEnv(contextlib.AbstractContextManager['TestEnv']):
141
PYTHON (for bash tests)
142
QEMU_PROG, QEMU_IMG_PROG, QEMU_IO_PROG, QEMU_NBD_PROG, QSD_PROG
143
"""
143
- self.python = sys.executable
144
+ self.python = str(Path(sys.executable).absolute())
145
+
146
+ # QEMU configure-time venv python executable
147
+ venv_python = Path(
148
+ os.path.join(self.build_root, "pyvenv", "bin", "python3")
149
+ ).absolute()
150
+
151
+ if self.python != str(venv_python):
152
+ runpath = os.path.join(self.build_root, "run")
153
+ cmd = ' '.join(shlex.quote(x) for x in sys.argv)
154
+ print(
155
+ "\n\033[93m\033[1mWARNING\033[0m: "
156
+ "iotests is being run from outside of the configure-time "
157
+ "python virtual environment\n\n"
158
+ f"current python: {self.python}\n"
159
+ f"pyvenv python: {venv_python}\n\n"
160
+ "Individual python tests will be executed inside the pyvenv,\n"
161
+ "but the test runner will continue to run outside.\n\n"
162
+ "\033[1mPlease use the meson run script:\033[0m\n"
163
+ f"\t{runpath} {cmd}\n",
164
+ file=sys.stderr
165
+ )
166
+ self.python = str(venv_python)
167
168
def root(*names: str) -> str:
169
return os.path.join(self.build_root, *names)