From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Daniel Berrange" <berrange@redhat.com>,
"Kevin Wolf" <kwolf@redhat.com>,
"Beraldo Leal" <bleal@redhat.com>, "John Snow" <jsnow@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Thomas Huth" <thuth@redhat.com>,
"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
"Kyle Evans" <kevans@freebsd.org>, "Warner Losh" <imp@bsdimp.com>,
qemu-block@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>,
"Michael Tsirkin" <mst@redhat.com>, "Ani Sinha" <ani@anisinha.ca>,
"Hanna Reitz" <hreitz@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: [RFC PATCH v3 6/7] iotests: use tests/venv for running tests
Date: Mon, 11 Jul 2022 19:01:54 -0400 [thread overview]
Message-ID: <20220711230155.953788-7-jsnow@redhat.com> (raw)
In-Reply-To: <20220711230155.953788-1-jsnow@redhat.com>
Essentially, the changes to testenv.py here mimic the changes that occur when
you "source venv/bin/activate.fish" or similar.
(1) update iotest's internal notion of which python binary to use,
(2) export the VIRTUAL_ENV variable,
(3) front-load the venv/bin directory to PATH.
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. The
subsequent commit attempts to address this shortcoming by teaching
iotests how to invoke the venv bootstrapper in this circumstance
instead.
Signed-off-by: John Snow <jsnow@redhat.com>
---
tests/qemu-iotests/testenv.py | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
index a864c74b123..29404ac94be 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', 'PATH',
+ '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',
@@ -102,18 +103,29 @@ def get_env(self) -> Dict[str, str]:
def init_directories(self) -> None:
"""Init directory variables:
+ VIRTUAL_ENV
+ PATH
PYTHONPATH
TEST_DIR
SOCK_DIR
SAMPLE_IMG_DIR
"""
+ 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)
- # Path where qemu goodies live in this source tree.
- qemu_srctree_path = Path(__file__, '../../../python').resolve()
+ self.path = os.pathsep.join((
+ str(venv_path / 'bin'),
+ os.environ['PATH'],
+ ))
self.pythonpath = os.pathsep.join(filter(None, (
self.source_iotests,
- str(qemu_srctree_path),
os.getenv('PYTHONPATH'),
)))
@@ -138,7 +150,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 +312,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.3
next prev parent reply other threads:[~2022-07-11 23:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-11 23:01 [RFC PATCH v3 0/7] tests: run python tests under a venv John Snow
2022-07-11 23:01 ` [RFC PATCH v3 1/7] tests: create optional tests/venv dependency groups John Snow
2022-07-11 23:01 ` [RFC PATCH v3 2/7] tests: pythonize test venv creation John Snow
2022-07-11 23:01 ` [RFC PATCH v3 3/7] tests: Remove spurious pip warnings on Ubuntu20.04 John Snow
2022-07-11 23:01 ` [RFC PATCH v3 4/7] tests/vm: add venv pre-requisites to VM building recipes John Snow
2022-07-11 23:01 ` [RFC PATCH v3 5/7] tests: add 'check-venv' as a dependency of 'make check' John Snow
2022-07-11 23:01 ` John Snow [this message]
2022-07-11 23:01 ` [RFC PATCH v3 7/7] iotests: self-bootstrap testing venv John Snow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220711230155.953788-7-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=ani@anisinha.ca \
--cc=berrange@redhat.com \
--cc=bleal@redhat.com \
--cc=crosa@redhat.com \
--cc=f4bug@amsat.org \
--cc=hreitz@redhat.com \
--cc=imp@bsdimp.com \
--cc=kevans@freebsd.org \
--cc=kwolf@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
--cc=wainersm@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).