Commit 0e0bf74cdd for qemu.org

commit 0e0bf74cddc65db27aca400671f147b7f33d8db4
Author: John Snow <jsnow@redhat.com>
Date:   Wed Feb 18 16:34:03 2026 -0500

    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>

diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
index 29caaa8a34..c357e6ebf5 100644
--- a/tests/qemu-iotests/testenv.py
+++ b/tests/qemu-iotests/testenv.py
@@ -20,6 +20,7 @@
 import sys
 import tempfile
 from pathlib import Path
+import shlex
 import shutil
 import collections
 import contextlib
@@ -140,7 +141,29 @@ def init_binaries(self) -> None:
              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)