[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 09/13] iotests: add 'qemu' package location to PYTHONPATH in teste
From: |
Kevin Wolf |
Subject: |
[PULL 09/13] iotests: add 'qemu' package location to PYTHONPATH in testenv |
Date: |
Wed, 6 Oct 2021 12:59:19 +0200 |
From: John Snow <jsnow@redhat.com>
We can drop the sys.path hacking in various places by doing
this. Additionally, by doing it in one place right up top, we can print
interesting warnings in case the environment does not look correct. (See
next commit.)
If we ever decide to change how the environment is crafted, all of the
"help me find my python packages" goop is all in one place, right in one
function.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20210923180715.4168522-2-jsnow@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
tests/qemu-iotests/iotests.py | 2 --
tests/qemu-iotests/testenv.py | 15 +++++++++------
tests/qemu-iotests/235 | 2 --
tests/qemu-iotests/297 | 6 ------
tests/qemu-iotests/300 | 5 ++---
tests/qemu-iotests/tests/mirror-top-perms | 7 +++----
6 files changed, 14 insertions(+), 23 deletions(-)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index ce06cf5630..b06ad76e0c 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -36,8 +36,6 @@
from contextlib import contextmanager
-# pylint: disable=import-error, wrong-import-position
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
from qemu.machine import qtest
from qemu.qmp import QMPMessage
diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
index 70da0d60c8..99a57a69f3 100644
--- a/tests/qemu-iotests/testenv.py
+++ b/tests/qemu-iotests/testenv.py
@@ -108,12 +108,15 @@ def init_directories(self) -> None:
SAMPLE_IMG_DIR
OUTPUT_DIR
"""
- self.pythonpath = os.getenv('PYTHONPATH')
- if self.pythonpath:
- self.pythonpath = self.source_iotests + os.pathsep + \
- self.pythonpath
- else:
- self.pythonpath = self.source_iotests
+
+ # Path where qemu goodies live in this source tree.
+ qemu_srctree_path = Path(__file__, '../../../python').resolve()
+
+ self.pythonpath = os.pathsep.join(filter(None, (
+ self.source_iotests,
+ str(qemu_srctree_path),
+ os.getenv('PYTHONPATH'),
+ )))
self.test_dir = os.getenv('TEST_DIR',
os.path.join(os.getcwd(), 'scratch'))
diff --git a/tests/qemu-iotests/235 b/tests/qemu-iotests/235
index 8aed45f9a7..4de920c380 100755
--- a/tests/qemu-iotests/235
+++ b/tests/qemu-iotests/235
@@ -24,8 +24,6 @@ import os
import iotests
from iotests import qemu_img_create, qemu_io, file_path, log
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-
from qemu.machine import QEMUMachine
iotests.script_initialize(supported_fmts=['qcow2'])
diff --git a/tests/qemu-iotests/297 b/tests/qemu-iotests/297
index b04cba5366..467b712280 100755
--- a/tests/qemu-iotests/297
+++ b/tests/qemu-iotests/297
@@ -68,12 +68,6 @@ def run_linters():
# Todo notes are fine, but fixme's or xxx's should probably just be
# fixed (in tests, at least)
env = os.environ.copy()
- qemu_module_path = os.path.join(os.path.dirname(__file__),
- '..', '..', 'python')
- try:
- env['PYTHONPATH'] += os.pathsep + qemu_module_path
- except KeyError:
- env['PYTHONPATH'] = qemu_module_path
subprocess.run(('pylint-3', '--score=n', '--notes=FIXME,XXX', *files),
env=env, check=False)
diff --git a/tests/qemu-iotests/300 b/tests/qemu-iotests/300
index fe94de84ed..10f9f2a8da 100755
--- a/tests/qemu-iotests/300
+++ b/tests/qemu-iotests/300
@@ -24,11 +24,10 @@ import random
import re
from typing import Dict, List, Optional
+from qemu.machine import machine
+
import iotests
-# Import qemu after iotests.py has amended sys.path
-# pylint: disable=wrong-import-order
-from qemu.machine import machine
BlockBitmapMapping = List[Dict[str, object]]
diff --git a/tests/qemu-iotests/tests/mirror-top-perms
b/tests/qemu-iotests/tests/mirror-top-perms
index 2fc8dd66e0..73138a0ef9 100755
--- a/tests/qemu-iotests/tests/mirror-top-perms
+++ b/tests/qemu-iotests/tests/mirror-top-perms
@@ -20,13 +20,12 @@
#
import os
-import iotests
-from iotests import qemu_img
-# Import qemu after iotests.py has amended sys.path
-# pylint: disable=wrong-import-order
import qemu
+import iotests
+from iotests import qemu_img
+
image_size = 1 * 1024 * 1024
source = os.path.join(iotests.test_dir, 'source.img')
--
2.31.1
- [PULL 00/13] Block layer patches, Kevin Wolf, 2021/10/06
- [PULL 02/13] qemu-storage-daemon: Only display FUSE help when FUSE is built-in, Kevin Wolf, 2021/10/06
- [PULL 01/13] include/block.h: remove outdated comment, Kevin Wolf, 2021/10/06
- [PULL 03/13] block: implement bdrv_new_open_driver_opts(), Kevin Wolf, 2021/10/06
- [PULL 04/13] block: bdrv_insert_node(): fix and improve error handling, Kevin Wolf, 2021/10/06
- [PULL 05/13] block: bdrv_insert_node(): doc and style, Kevin Wolf, 2021/10/06
- [PULL 06/13] block: bdrv_insert_node(): don't use bdrv_open(), Kevin Wolf, 2021/10/06
- [PULL 07/13] iotests/image-fleecing: declare requirement of copy-before-write, Kevin Wolf, 2021/10/06
- [PULL 08/13] block: introduce max_hw_iov for use in scsi-generic, Kevin Wolf, 2021/10/06
- [PULL 10/13] iotests/linters: check mypy files all at once, Kevin Wolf, 2021/10/06
- [PULL 09/13] iotests: add 'qemu' package location to PYTHONPATH in testenv,
Kevin Wolf <=
- [PULL 11/13] iotests/mirror-top-perms: Adjust imports, Kevin Wolf, 2021/10/06
- [PULL 12/13] iotests/migrate-bitmaps-test: delint, Kevin Wolf, 2021/10/06
- [PULL 13/13] iotests: Update for pylint 2.11.1, Kevin Wolf, 2021/10/06
- Re: [PULL 00/13] Block layer patches, Richard Henderson, 2021/10/06