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 <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>
This commit is contained in:
John Snow 2021-09-23 14:07:10 -04:00 committed by Kevin Wolf
parent cc07162953
commit af6d4c56e1
6 changed files with 14 additions and 23 deletions

View file

@ -24,8 +24,6 @@ import os
import iotests import iotests
from iotests import qemu_img_create, qemu_io, file_path, log 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 from qemu.machine import QEMUMachine
iotests.script_initialize(supported_fmts=['qcow2']) iotests.script_initialize(supported_fmts=['qcow2'])

View file

@ -68,12 +68,6 @@ def run_linters():
# Todo notes are fine, but fixme's or xxx's should probably just be # Todo notes are fine, but fixme's or xxx's should probably just be
# fixed (in tests, at least) # fixed (in tests, at least)
env = os.environ.copy() 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), subprocess.run(('pylint-3', '--score=n', '--notes=FIXME,XXX', *files),
env=env, check=False) env=env, check=False)

View file

@ -24,11 +24,10 @@ import random
import re import re
from typing import Dict, List, Optional from typing import Dict, List, Optional
from qemu.machine import machine
import iotests 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]] BlockBitmapMapping = List[Dict[str, object]]

View file

@ -36,8 +36,6 @@ import unittest
from contextlib import contextmanager 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.machine import qtest
from qemu.qmp import QMPMessage from qemu.qmp import QMPMessage

View file

@ -108,12 +108,15 @@ class TestEnv(ContextManager['TestEnv']):
SAMPLE_IMG_DIR SAMPLE_IMG_DIR
OUTPUT_DIR OUTPUT_DIR
""" """
self.pythonpath = os.getenv('PYTHONPATH')
if self.pythonpath: # Path where qemu goodies live in this source tree.
self.pythonpath = self.source_iotests + os.pathsep + \ qemu_srctree_path = Path(__file__, '../../../python').resolve()
self.pythonpath
else: self.pythonpath = os.pathsep.join(filter(None, (
self.pythonpath = self.source_iotests self.source_iotests,
str(qemu_srctree_path),
os.getenv('PYTHONPATH'),
)))
self.test_dir = os.getenv('TEST_DIR', self.test_dir = os.getenv('TEST_DIR',
os.path.join(os.getcwd(), 'scratch')) os.path.join(os.getcwd(), 'scratch'))

View file

@ -20,13 +20,12 @@
# #
import os import os
import qemu
import iotests import iotests
from iotests import qemu_img from iotests import qemu_img
# Import qemu after iotests.py has amended sys.path
# pylint: disable=wrong-import-order
import qemu
image_size = 1 * 1024 * 1024 image_size = 1 * 1024 * 1024
source = os.path.join(iotests.test_dir, 'source.img') source = os.path.join(iotests.test_dir, 'source.img')