From 3b9a781e138830a190d16c8dd970b800a086de46 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Wed, 4 Aug 2021 13:00:53 +0200 Subject: [PATCH 1/3] edd_test: Locate the edd_data based on the test file location We can't use the blivet.edd module location when running tests against installed version of blivet. --- tests/devicelibs_test/edd_test.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/devicelibs_test/edd_test.py b/tests/devicelibs_test/edd_test.py index 23d736f4..7ec8d1e6 100644 --- a/tests/devicelibs_test/edd_test.py +++ b/tests/devicelibs_test/edd_test.py @@ -1,7 +1,6 @@ import unittest import mock import os -import inspect import logging import copy @@ -110,9 +109,9 @@ class EddTestCase(unittest.TestCase): name = name[:-1] if name.startswith("/"): name = name[1:] - dirname = os.path.dirname(inspect.getfile(edd)) + dirname = os.path.abspath(os.path.dirname(__file__)) return os.path.join(dirname, - "../../tests/devicelibs_test/edd_data/", + "edd_data/", name) def edd_debug(self, *args): -- 2.31.1 From 7ad3824fceb98e2741820b76a9cfea5add338343 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Wed, 4 Aug 2021 13:02:08 +0200 Subject: [PATCH 2/3] tests: Allow running tests without the tests directory in PYTHONPATH When running the tests against installed version of blivet, the "tests" directory is not in PYTHONPATH so we need to import all helper modules using relative path. --- tests/action_test.py | 2 +- tests/devicelibs_test/edd_test.py | 2 +- tests/{ => devicelibs_test}/lib.py | 0 tests/formats_test/fs_test.py | 2 +- tests/formats_test/fslabeling.py | 2 +- tests/formats_test/fstesting.py | 2 +- tests/formats_test/fsuuid.py | 2 +- tests/formats_test/labeling_test.py | 2 +- tests/{ => formats_test}/loopbackedtestcase.py | 0 tests/formats_test/luks_test.py | 2 +- tests/formats_test/lvmpv_test.py | 2 +- tests/partitioning_test.py | 2 +- 12 files changed, 10 insertions(+), 10 deletions(-) rename tests/{ => devicelibs_test}/lib.py (100%) rename tests/{ => formats_test}/loopbackedtestcase.py (100%) diff --git a/tests/action_test.py b/tests/action_test.py index 38a2e872..1e84c20b 100644 --- a/tests/action_test.py +++ b/tests/action_test.py @@ -6,7 +6,7 @@ if PY3: else: from mock import Mock -from tests.storagetestcase import StorageTestCase +from storagetestcase import StorageTestCase import blivet from blivet.formats import get_format from blivet.size import Size diff --git a/tests/devicelibs_test/edd_test.py b/tests/devicelibs_test/edd_test.py index 7ec8d1e6..379c7aeb 100644 --- a/tests/devicelibs_test/edd_test.py +++ b/tests/devicelibs_test/edd_test.py @@ -6,7 +6,7 @@ import copy from blivet import arch from blivet.devicelibs import edd -from tests import lib +from . import lib class FakeDevice(object): diff --git a/tests/lib.py b/tests/devicelibs_test/lib.py similarity index 100% rename from tests/lib.py rename to tests/devicelibs_test/lib.py diff --git a/tests/formats_test/fs_test.py b/tests/formats_test/fs_test.py index ab3499a7..bd643370 100644 --- a/tests/formats_test/fs_test.py +++ b/tests/formats_test/fs_test.py @@ -10,7 +10,7 @@ from blivet.errors import DeviceFormatError from blivet.formats import get_format from blivet.devices import PartitionDevice, DiskDevice -from tests import loopbackedtestcase +from . import loopbackedtestcase from . import fstesting diff --git a/tests/formats_test/fslabeling.py b/tests/formats_test/fslabeling.py index fbb28eee..0e0dc261 100644 --- a/tests/formats_test/fslabeling.py +++ b/tests/formats_test/fslabeling.py @@ -2,7 +2,7 @@ import abc import six -from tests import loopbackedtestcase +from . import loopbackedtestcase from blivet.errors import FSError, FSReadLabelError from blivet.size import Size diff --git a/tests/formats_test/fstesting.py b/tests/formats_test/fstesting.py index 86b2a116..e34584d8 100644 --- a/tests/formats_test/fstesting.py +++ b/tests/formats_test/fstesting.py @@ -5,7 +5,7 @@ from six import add_metaclass import os import tempfile -from tests import loopbackedtestcase +from . import loopbackedtestcase from blivet.errors import FSError, FSResizeError, DeviceFormatError from blivet.size import Size, ROUND_DOWN from blivet.formats import fs diff --git a/tests/formats_test/fsuuid.py b/tests/formats_test/fsuuid.py index c8003945..16aa19a6 100644 --- a/tests/formats_test/fsuuid.py +++ b/tests/formats_test/fsuuid.py @@ -3,7 +3,7 @@ import abc import six from unittest import skipIf -from tests import loopbackedtestcase +from . import loopbackedtestcase from blivet.errors import FSError, FSWriteUUIDError from blivet.size import Size from blivet.util import capture_output diff --git a/tests/formats_test/labeling_test.py b/tests/formats_test/labeling_test.py index e26cb7df..d24e6619 100644 --- a/tests/formats_test/labeling_test.py +++ b/tests/formats_test/labeling_test.py @@ -1,10 +1,10 @@ import unittest -from tests import loopbackedtestcase from blivet.formats import device_formats import blivet.formats.fs as fs import blivet.formats.swap as swap +from . import loopbackedtestcase from . import fslabeling diff --git a/tests/loopbackedtestcase.py b/tests/formats_test/loopbackedtestcase.py similarity index 100% rename from tests/loopbackedtestcase.py rename to tests/formats_test/loopbackedtestcase.py diff --git a/tests/formats_test/luks_test.py b/tests/formats_test/luks_test.py index be0d50b0..5423ebdf 100644 --- a/tests/formats_test/luks_test.py +++ b/tests/formats_test/luks_test.py @@ -7,7 +7,7 @@ from blivet.formats.luks import LUKS from blivet.size import Size -from tests import loopbackedtestcase +from . import loopbackedtestcase class LUKSTestCase(loopbackedtestcase.LoopBackedTestCase): diff --git a/tests/formats_test/lvmpv_test.py b/tests/formats_test/lvmpv_test.py index 792a2f1d..da7270d9 100644 --- a/tests/formats_test/lvmpv_test.py +++ b/tests/formats_test/lvmpv_test.py @@ -4,7 +4,7 @@ from blivet.formats.lvmpv import LVMPhysicalVolume from blivet.size import Size -from tests import loopbackedtestcase +from . import loopbackedtestcase class LVMPVTestCase(loopbackedtestcase.LoopBackedTestCase): diff --git a/tests/partitioning_test.py b/tests/partitioning_test.py index b7aa5045..a713aaa1 100644 --- a/tests/partitioning_test.py +++ b/tests/partitioning_test.py @@ -29,7 +29,7 @@ from blivet.devices.lvm import LVMCacheRequest from blivet.errors import PartitioningError -from tests.imagebackedtestcase import ImageBackedTestCase +from imagebackedtestcase import ImageBackedTestCase from blivet.blivet import Blivet from blivet.util import sparsetmpfile from blivet.formats import get_format -- 2.31.1 From 9ee41c8b60c56ce752e305be73001c7089f43011 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Fri, 6 Aug 2021 14:51:01 +0200 Subject: [PATCH 3/3] tests: Print version and blivet location when running tests --- tests/run_tests.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/run_tests.py b/tests/run_tests.py index 32e3f2d3..8ad8b61a 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -32,6 +32,11 @@ if __name__ == '__main__': testdir = os.path.abspath(os.path.dirname(__file__)) + import blivet + print("Running tests with Blivet %s from %s" % (blivet.__version__, + os.path.abspath(os.path.dirname(blivet.__file__))), + file=sys.stderr) + if args.testname: for n in args.testname: suite.addTests(unittest.TestLoader().loadTestsFromName(n)) -- 2.31.1