Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dedicated DISABLED() function to disable tests in Python test framework #5792

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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