Browse Source

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>
master
John Snow 1 month ago
parent
commit
0e0bf74cdd
  1. 25
      tests/qemu-iotests/testenv.py

25
tests/qemu-iotests/testenv.py

@ -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)

Loading…
Cancel
Save