Skip to content

Commit af6d4c5

Browse files
jnsnowkevmw
authored andcommitted
iotests: add 'qemu' package location to PYTHONPATH in testenv
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 <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]> Reviewed-by: Kevin Wolf <[email protected]> Message-Id: <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent cc07162 commit af6d4c5

File tree

6 files changed

+14
-23
lines changed

6 files changed

+14
-23
lines changed

tests/qemu-iotests/235

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import os
2424
import iotests
2525
from iotests import qemu_img_create, qemu_io, file_path, log
2626

27-
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
28-
2927
from qemu.machine import QEMUMachine
3028

3129
iotests.script_initialize(supported_fmts=['qcow2'])

tests/qemu-iotests/297

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ def run_linters():
6868
# Todo notes are fine, but fixme's or xxx's should probably just be
6969
# fixed (in tests, at least)
7070
env = os.environ.copy()
71-
qemu_module_path = os.path.join(os.path.dirname(__file__),
72-
'..', '..', 'python')
73-
try:
74-
env['PYTHONPATH'] += os.pathsep + qemu_module_path
75-
except KeyError:
76-
env['PYTHONPATH'] = qemu_module_path
7771
subprocess.run(('pylint-3', '--score=n', '--notes=FIXME,XXX', *files),
7872
env=env, check=False)
7973

tests/qemu-iotests/300

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ import random
2424
import re
2525
from typing import Dict, List, Optional
2626

27+
from qemu.machine import machine
28+
2729
import iotests
2830

29-
# Import qemu after iotests.py has amended sys.path
30-
# pylint: disable=wrong-import-order
31-
from qemu.machine import machine
3231

3332
BlockBitmapMapping = List[Dict[str, object]]
3433

tests/qemu-iotests/iotests.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636

3737
from contextlib import contextmanager
3838

39-
# pylint: disable=import-error, wrong-import-position
40-
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
4139
from qemu.machine import qtest
4240
from qemu.qmp import QMPMessage
4341

tests/qemu-iotests/testenv.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,15 @@ def init_directories(self) -> None:
108108
SAMPLE_IMG_DIR
109109
OUTPUT_DIR
110110
"""
111-
self.pythonpath = os.getenv('PYTHONPATH')
112-
if self.pythonpath:
113-
self.pythonpath = self.source_iotests + os.pathsep + \
114-
self.pythonpath
115-
else:
116-
self.pythonpath = self.source_iotests
111+
112+
# Path where qemu goodies live in this source tree.
113+
qemu_srctree_path = Path(__file__, '../../../python').resolve()
114+
115+
self.pythonpath = os.pathsep.join(filter(None, (
116+
self.source_iotests,
117+
str(qemu_srctree_path),
118+
os.getenv('PYTHONPATH'),
119+
)))
117120

118121
self.test_dir = os.getenv('TEST_DIR',
119122
os.path.join(os.getcwd(), 'scratch'))

tests/qemu-iotests/tests/mirror-top-perms

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
#
2121

2222
import os
23-
import iotests
24-
from iotests import qemu_img
2523

26-
# Import qemu after iotests.py has amended sys.path
27-
# pylint: disable=wrong-import-order
2824
import qemu
2925

26+
import iotests
27+
from iotests import qemu_img
28+
3029

3130
image_size = 1 * 1024 * 1024
3231
source = os.path.join(iotests.test_dir, 'source.img')

0 commit comments

Comments
 (0)