[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 9/9] iotests: use tests/venv for running tests
From: |
John Snow |
Subject: |
[RFC PATCH 9/9] iotests: use tests/venv for running tests |
Date: |
Thu, 12 May 2022 20:06:09 -0400 |
Essentially, this:
(A) adjusts the python binary to be the one found in the venv (which is
a symlink to the python binary chosen at configure time)
(B) adds a new VIRTUAL_ENV export variable
(C) changes PATH to front-load the venv binary directory.
If the venv directory isn't found, raise a friendly exception that tries
to give the human operator a friendly clue as to what's gone wrong. In
the very near future, I'd like to teach iotests how to fix this problem
entirely of its own volition, but that's a trick for a little later.
Signed-off-by: John Snow <jsnow@redhat.com>
---
tests/qemu-iotests/testenv.py | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
index 0007da3f06c..fd3720ed7e7 100644
--- a/tests/qemu-iotests/testenv.py
+++ b/tests/qemu-iotests/testenv.py
@@ -65,8 +65,9 @@ class TestEnv(ContextManager['TestEnv']):
# lot of them. Silence pylint:
# pylint: disable=too-many-instance-attributes
- env_variables = ['PYTHONPATH', 'TEST_DIR', 'SOCK_DIR', 'SAMPLE_IMG_DIR',
- 'PYTHON', 'QEMU_PROG', 'QEMU_IMG_PROG',
+ env_variables = ['PYTHONPATH', 'VIRTUAL_ENV', 'PYTHON',
+ 'TEST_DIR', 'SOCK_DIR', 'SAMPLE_IMG_DIR',
+ 'QEMU_PROG', 'QEMU_IMG_PROG',
'QEMU_IO_PROG', 'QEMU_NBD_PROG', 'QSD_PROG',
'QEMU_OPTIONS', 'QEMU_IMG_OPTIONS',
'QEMU_IO_OPTIONS', 'QEMU_IO_OPTIONS_NO_FMT',
@@ -98,6 +99,10 @@ def get_env(self) -> Dict[str, str]:
if val is not None:
env[v] = val
+ env['PATH'] = os.pathsep.join((
+ os.path.join(self.virtual_env, 'bin'),
+ os.environ['PATH']
+ ))
return env
def init_directories(self) -> None:
@@ -107,13 +112,17 @@ def init_directories(self) -> None:
SOCK_DIR
SAMPLE_IMG_DIR
"""
-
- # Path where qemu goodies live in this source tree.
- qemu_srctree_path = Path(__file__, '../../../python').resolve()
+ venv_path = Path(self.build_root, 'tests/venv/')
+ if not venv_path.exists():
+ raise FileNotFoundError(
+ f"Virtual environment \"{venv_path!s}\" isn't found."
+ " (Maybe you need to run 'make check-venv'"
+ " from the build dir?)"
+ )
+ self.virtual_env: str = str(venv_path)
self.pythonpath = os.pathsep.join(filter(None, (
self.source_iotests,
- str(qemu_srctree_path),
os.getenv('PYTHONPATH'),
)))
@@ -138,7 +147,7 @@ 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 = os.path.join(self.virtual_env, 'bin', 'python3')
def root(*names: str) -> str:
return os.path.join(self.build_root, *names)
@@ -300,6 +309,7 @@ def print_env(self, prefix: str = '') -> None:
{prefix}GDB_OPTIONS -- {GDB_OPTIONS}
{prefix}VALGRIND_QEMU -- {VALGRIND_QEMU}
{prefix}PRINT_QEMU_OUTPUT -- {PRINT_QEMU}
+{prefix}VIRTUAL_ENV -- {VIRTUAL_ENV}
{prefix}"""
args = collections.defaultdict(str, self.get_env())
--
2.34.1
- Re: [RFC PATCH 4/9] tests: silence pip upgrade warnings during venv creation, (continued)
- [RFC PATCH 3/9] tests: install "qemu" namespace package into venv, John Snow, 2022/05/12
- [RFC PATCH 5/9] tests: use tests/venv to run basevm.py-based scripts, John Snow, 2022/05/12
- [RFC PATCH 8/9] iotests: fix source directory location, John Snow, 2022/05/12
- [RFC PATCH 7/9] tests: add check-venv to build-tcg-disabled CI recipe, John Snow, 2022/05/12
- [RFC PATCH 9/9] iotests: use tests/venv for running tests,
John Snow <=
- Re: [RFC PATCH 9/9] iotests: use tests/venv for running tests, Paolo Bonzini, 2022/05/13
- Re: [RFC PATCH 9/9] iotests: use tests/venv for running tests, John Snow, 2022/05/13
- Re: [RFC PATCH 9/9] iotests: use tests/venv for running tests, Paolo Bonzini, 2022/05/13
- Re: [RFC PATCH 9/9] iotests: use tests/venv for running tests, John Snow, 2022/05/13
- Re: [RFC PATCH 9/9] iotests: use tests/venv for running tests, John Snow, 2022/05/14
- Re: [RFC PATCH 9/9] iotests: use tests/venv for running tests, Paolo Bonzini, 2022/05/16
- Re: [RFC PATCH 9/9] iotests: use tests/venv for running tests, John Snow, 2022/05/17
- Re: [RFC PATCH 9/9] iotests: use tests/venv for running tests, Paolo Bonzini, 2022/05/18
Re: [RFC PATCH 0/9] tests: run python tests under the build/tests/venv environment, Daniel P . Berrangé, 2022/05/13