Skip to content

Commit

Permalink
Merge pull request #5792 from grom72/test-py-disable
Browse files Browse the repository at this point in the history
Use dedicated DISABLED() function to disable tests in Python test framework
  • Loading branch information
janekmi authored Jul 13, 2023
2 parents 7803d61 + 8b9b4fb commit 8f1c1e0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
16 changes: 13 additions & 3 deletions src/test/RUNTESTS.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,13 @@ def run_tests(self):
try:
t = tc()
if t.enabled:
self.msg.print('{}: SETUP\t({}/{})'
.format(t, t.test_type, c))
t._execute(c)
if t.force_disabled:
self._test_disabled(t, c)
continue
else:
self.msg.print('{}: SETUP\t({}/{})'
.format(t, t.test_type, c))
t._execute(c)
else:
continue

Expand Down Expand Up @@ -153,6 +157,12 @@ def _test_passed(self, tc):
self.msg.print('{}: {}PASS{} {}'
.format(tc, futils.Color.GREEN, futils.Color.END, tm))

def _test_disabled(self, tc, context):
"""Print message specific for disabled test"""
self.msg.print('{}: {}DISABLED{}\t({}/{})'
.format(tc, futils.Color.YELLOW, futils.Color.END,
tc.test_type, context))


def _import_testfiles():
"""
Expand Down
18 changes: 12 additions & 6 deletions src/test/pmem2_badblock/TESTS.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def run_test(self, ctx, filepath):


# XXX - https://github.com/pmem/pmdk/issues/5636
class DISABLE_TEST0(PMEM2_BADBLOCK_COUNT):
@t.DISABLED()
class TEST0(PMEM2_BADBLOCK_COUNT):
"""
compares the number of bad blocks returned by pmem2 and ndctl on fsdax
"""
Expand All @@ -80,8 +81,9 @@ def run(self, ctx):


# XXX - https://github.com/pmem/pmdk/issues/5636
@t.DISABLED()
@t.require_devdax(t.DevDax('devdax1'))
class DISABLE_TEST1(PMEM2_BADBLOCK_COUNT):
class TEST1(PMEM2_BADBLOCK_COUNT):
"""
compares the number of bad blocks returned by pmem2 and ndctl on devdax
"""
Expand All @@ -93,7 +95,8 @@ def run(self, ctx):


# XXX - https://github.com/pmem/pmdk/issues/5636
class DISABLE_TEST2(PMEM2_BADBLOCK):
@t.DISABLED()
class TEST2(PMEM2_BADBLOCK):
"""test mcsafe read operation with encountered badblock"""
test_case = "test_pmem2_src_mcsafe_badblock_read"

Expand All @@ -103,7 +106,8 @@ def run(self, ctx):


# XXX - https://github.com/pmem/pmdk/issues/5636
class DISABLE_TEST3(PMEM2_BADBLOCK):
@t.DISABLED()
class TEST3(PMEM2_BADBLOCK):
"""test mcsafe write operation with encountered badblock"""
test_case = "test_pmem2_src_mcsafe_badblock_write"

Expand All @@ -113,8 +117,9 @@ def run(self, ctx):


# XXX - https://github.com/pmem/pmdk/issues/5636
@t.DISABLED()
@t.require_devdax(t.DevDax('devdax1'))
class DISABLE_TEST4(PMEM2_BADBLOCK):
class TEST4(PMEM2_BADBLOCK):
"""test mcsafe read operation with encountered badblock on devdax"""
test_case = "test_pmem2_src_mcsafe_badblock_read"

Expand All @@ -124,8 +129,9 @@ def run(self, ctx):


# XXX - https://github.com/pmem/pmdk/issues/5636
@t.DISABLED()
@t.require_devdax(t.DevDax('devdax1'))
class DISABLE_TEST5(PMEM2_BADBLOCK):
class TEST5(PMEM2_BADBLOCK):
"""test mcsafe write operation with encountered badblock on devdax"""
test_case = "test_pmem2_src_mcsafe_badblock_write"

Expand Down
4 changes: 4 additions & 0 deletions src/test/unittest/basetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,13 @@ class BaseTest(metaclass=_TestCase):
Attributes:
enabled (bool): True if test is meant to be executed, False otherwise.
Defaults to True.
force_disabled (bool): True if the test is explicitle excluded from
execution e.g. in case the test fails permanently.
Defaults to False.
ctx (Context): context affiliated with the test
"""
enabled = True
force_disabled = False

def __init__(self):
self.ctx = None
Expand Down
1 change: 1 addition & 0 deletions src/test/unittest/futils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Color:
"""
RED = '\33[91m'
GREEN = '\33[92m'
YELLOW = '\33[93m'
END = '\33[0m'


Expand Down
13 changes: 13 additions & 0 deletions src/test/unittest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,16 @@ def wrapped(tc):
return tc

return wrapped


def DISABLED(**kwargs):
"""
DISABLE a given test.
Used as a test class (tc) decorator.
"""

def wrapped(tc):
tc.force_disabled = True

return wrapped

0 comments on commit 8f1c1e0

Please sign in to comment.