aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2021-08-05 12:15:53 -0400
committerJake Hunsaker <jhunsake@redhat.com>2021-08-10 10:24:53 -0400
commit813e71f37ebdd1e6ad4e58e9f3845d6acf6a5dbf (patch)
tree1f85064d9a5a9bb33acd5b7a66ed25baa2a415a0 /tests
parenta4415d3d979ff2610ffdbb7569bf9da6e16f3d5d (diff)
downloadsos-813e71f37ebdd1e6ad4e58e9f3845d6acf6a5dbf.tar.gz
[tests] Allow entire test classes to be distro specific
Previously new test cases had to be written in such a way that they could be run on any supported distribution, even if their individual tests were all marked for specific distributions. Use of the distro-only decorators would fail when applied to test cases as a whole due to how test instantiation errors are handled. To address this, provide a distro check within `BaseSoSTest` so that tests can be made distro-specific and we can signal to avocado to skip all tests within that test case without failing the test suite entirely. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/sos_tests.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/sos_tests.py b/tests/sos_tests.py
index 56c3f0b0..5d253f5a 100644
--- a/tests/sos_tests.py
+++ b/tests/sos_tests.py
@@ -66,6 +66,8 @@ class BaseSoSTest(Test):
_exception_expected = False
sos_cmd = ''
sos_timeout = 300
+ redhat_only = False
+ ubuntu_only = False
@property
def klass_name(self):
@@ -199,12 +201,31 @@ class BaseSoSTest(Test):
}
return sinfo
+ def check_distro_for_enablement(self):
+ """Check if the test case is meant only for a specific distro family,
+ and if it is and we are not running on that family, skip all the tests
+ for that test case.
+
+ This allows us to define distro-specific test classes much the same way
+ we can define distro-specific tests _within_ a test class using the
+ appropriate decorators. We can't use the decorators for the class however
+ due to how avocado catches instantiation exceptions, so instead we need
+ to raise the skip exception after instantiation is done.
+ """
+ if self.redhat_only:
+ if self.local_distro not in RH_DIST:
+ raise TestSkipError('Not running on a Red Hat distro')
+ elif self.ubuntu_only:
+ if self.local_distro not in UBUNTU_DIST:
+ raise TestSkipError("Not running on a Ubuntu or Debian distro")
+
def setUp(self):
"""Setup the tmpdir and any needed mocking for the test, then execute
the defined sos command. Ensure that we only run the sos command once
for every test case, instead of once for every test_* method defined.
"""
self.local_distro = distro.detect().name
+ self.check_distro_for_enablement()
# check to prevent multiple setUp() runs
if not os.path.isdir(self.tmpdir):
# setup our class-shared tmpdir