[PATCH] iotests: fix false positive on running-outside-venv warning

John Snow posted 1 patch 1 month, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261007183338.1899422-1-jsnow@redhat.com
Maintainers: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>
tests/qemu-iotests/testenv.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
[PATCH] iotests: fix false positive on running-outside-venv warning
Posted by John Snow 1 month, 2 weeks ago
Currently, iotests checks to see if you are running with the "correct"
python interpreter by checking string equivalence between your current
python and the configure-time venv python.

Depending on exactly *how* you launch or configure your python,
however, this warning may produce false positives because it treats
"python" as different from "python3" as different from
e.g. "python3.12", even though they are all actually the same exact
interpreter.

This patch fixes this by comparing only the parent directories; we
will now be happy with any interpreter so long as it is located within
build/pyvenv/bin/.

Note that we cannot fix this by resolving symlinks, as python venv
binaries are often (but not always) just symlinks to /usr/bin/<etc>,
and full resolution would produce even more false negatives.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: John Snow <jsnow@redhat.com>
---
 tests/qemu-iotests/testenv.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
index 86bcdf7cfad..53c9b5d1968 100644
--- a/tests/qemu-iotests/testenv.py
+++ b/tests/qemu-iotests/testenv.py
@@ -86,7 +86,7 @@ def prepare_subprocess(self, args: List[str]) -> Dict[str, str]:
         with open(args[0], encoding="utf-8") as f:
             try:
                 if f.readline().rstrip() == '#!/usr/bin/env python3':
-                    args.insert(0, self.python)
+                    args.insert(0, str(self.python))
             except UnicodeDecodeError:  # binary test? for future.
                 pass
 
@@ -141,14 +141,14 @@ def init_binaries(self) -> None:
              PYTHON (for bash tests)
              QEMU_PROG, QEMU_IMG_PROG, QEMU_IO_PROG, QEMU_NBD_PROG, QSD_PROG
         """
-        self.python = str(Path(sys.executable).absolute())
+        self.python = 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):
+        if str(self.python.parent) != str(venv_python.parent):
             runpath = os.path.join(self.build_root, "run")
             cmd = ' '.join(shlex.quote(x) for x in sys.argv)
             print(
@@ -163,7 +163,7 @@ def init_binaries(self) -> None:
                 f"\t{runpath} {cmd}\n",
                 file=sys.stderr
             )
-            self.python = str(venv_python)
+            self.python = venv_python
 
         def root(*names: str) -> str:
             return os.path.join(self.build_root, *names)
-- 
2.55.0
Re: [PATCH] iotests: fix false positive on running-outside-venv warning
Posted by Kevin Wolf 1 week, 3 days ago
Am 07.10.2026 um 20:33 hat John Snow geschrieben:
> Currently, iotests checks to see if you are running with the "correct"
> python interpreter by checking string equivalence between your current
> python and the configure-time venv python.
> 
> Depending on exactly *how* you launch or configure your python,
> however, this warning may produce false positives because it treats
> "python" as different from "python3" as different from
> e.g. "python3.12", even though they are all actually the same exact
> interpreter.
> 
> This patch fixes this by comparing only the parent directories; we
> will now be happy with any interpreter so long as it is located within
> build/pyvenv/bin/.
> 
> Note that we cannot fix this by resolving symlinks, as python venv
> binaries are often (but not always) just symlinks to /usr/bin/<etc>,
> and full resolution would produce even more false negatives.
> 
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: John Snow <jsnow@redhat.com>

Thanks, applied to the block branch.

Kevin