]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
iotests: tolerate being run outside of pyvenv
authorJohn Snow <jsnow@redhat.com>
Wed, 18 Feb 2026 21:34:03 +0000 (16:34 -0500)
committerJohn Snow <jsnow@redhat.com>
Mon, 23 Feb 2026 18:24:42 +0000 (13:24 -0500)
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>
tests/qemu-iotests/testenv.py

index 29caaa8a349c32aad307d477c4b01cec09662ba9..c357e6ebf503316fc3056162217be379948b4502 100644 (file)
@@ -20,6 +20,7 @@ import os
 import sys
 import tempfile
 from pathlib import Path
+import shlex
 import shutil
 import collections
 import contextlib
@@ -140,7 +141,29 @@ class TestEnv(contextlib.AbstractContextManager['TestEnv']):
              PYTHON (for bash tests)
              QEMU_PROG, QEMU_IMG_PROG, QEMU_IO_PROG, QEMU_NBD_PROG, QSD_PROG
         """
-        self.python = sys.executable
+        self.python = str(Path(sys.executable).absolute())
+
+        # QEMU configure-time venv python executable
+        venv_python = Path(
+            os.path.join(self.build_root, "pyvenv", "bin", "python3")
+        ).absolute()
+
+        if self.python != str(venv_python):
+            runpath = os.path.join(self.build_root, "run")
+            cmd = ' '.join(shlex.quote(x) for x in sys.argv)
+            print(
+                "\n\033[93m\033[1mWARNING\033[0m: "
+                "iotests is being run from outside of the configure-time "
+                "python virtual environment\n\n"
+                f"current python: {self.python}\n"
+                f"pyvenv python:  {venv_python}\n\n"
+                "Individual python tests will be executed inside the pyvenv,\n"
+                "but the test runner will continue to run outside.\n\n"
+                "\033[1mPlease use the meson run script:\033[0m\n"
+                f"\t{runpath} {cmd}\n",
+                file=sys.stderr
+            )
+            self.python = str(venv_python)
 
         def root(*names: str) -> str:
             return os.path.join(self.build_root, *names)