]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
iotests: add 'qemu' package location to PYTHONPATH in testenv
authorJohn Snow <jsnow@redhat.com>
Thu, 23 Sep 2021 18:07:10 +0000 (14:07 -0400)
committerKevin Wolf <kwolf@redhat.com>
Wed, 6 Oct 2021 08:25:55 +0000 (10:25 +0200)
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/235
tests/qemu-iotests/297
tests/qemu-iotests/300
tests/qemu-iotests/iotests.py
tests/qemu-iotests/testenv.py
tests/qemu-iotests/tests/mirror-top-perms

index 8aed45f9a76eb3e7bf1e0a263e4c6034a21b3149..4de920c3801b05881cd1eb476ee74cf4a3fc3d86 100755 (executable)
@@ -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'])
index b04cba53667f52fafd1dafbe4a9f0e47ee7a5da4..467b712280e17e0cad7379cad0e8045732bb3c00 100755 (executable)
@@ -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)
 
index fe94de84edd94cd6f926f52312fd1d160aedbfad..10f9f2a8da68fe4f2d6d023c44e7b79abadbdc80 100755 (executable)
@@ -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]]
 
index ce06cf5630489a3e86b232a0bf48c8bce684ce36..b06ad76e0c5d7b5c30e83605e7be9091bc7fd0ad 100644 (file)
@@ -36,8 +36,6 @@ import unittest
 
 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
 
index 70da0d60c80a6a99dea035bf0370d598f9eb1f43..99a57a69f3a2484a063b962c50336410cd56003b 100644 (file)
@@ -108,12 +108,15 @@ class TestEnv(ContextManager['TestEnv']):
              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'))
index 2fc8dd66e0ab24aeab11350de24793b7940ce17b..73138a0ef912472d44dfc1c5637f5b09188c4813 100755 (executable)
 #
 
 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')