Skip to content

Commit

Permalink
clean up variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Dec 9, 2024
1 parent 51888e0 commit 7f88031
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions utils/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ def _ensure_jira_ticket_as_reason(item, reason: str):
pytest.exit(f"Please set a jira ticket for {nodeid}, instead of reason: {reason}", 1)


def _get_expected_failure_item(item, skip_reason, noxfail):
def _get_expected_failure_item(item, skip_reason, skip_test):
if inspect.isfunction(item) or inspect.isclass(item):
if not hasattr(item, "pytestmark"):
setattr(item, "pytestmark", [])

if noxfail:
if skip_test:
item.pytestmark.append(pytest.mark.skip(reason=skip_reason))
else:
item.pytestmark.append(pytest.mark.xfail(reason=skip_reason))
Expand All @@ -65,7 +65,7 @@ def _get_expected_failure_item(item, skip_reason, noxfail):
return item


def _should_skip(condition=None, library=None, weblog_variant=None):
def _expected_to_fail(condition=None, library=None, weblog_variant=None):
if condition is False:
return False

Expand Down Expand Up @@ -94,55 +94,53 @@ def _should_skip(condition=None, library=None, weblog_variant=None):
return True


def decorator(skip, noxfail, condition, decorator_type, reason, function_or_class):
def decorator(expected_to_fail, skip_test, condition, decorator_type, reason, function_or_class):
if inspect.isclass(function_or_class):
assert condition is not None, _MANIFEST_ERROR_MESSAGE

if decorator_type in ("bug", "flaky"):
_ensure_jira_ticket_as_reason(function_or_class, reason)

full_reason = decorator_type if reason is None else f"{decorator_type} ({reason})"
if not skip:
if not expected_to_fail:
return function_or_class
return _get_expected_failure_item(function_or_class, full_reason, noxfail)
return _get_expected_failure_item(function_or_class, full_reason, skip_test)


def missing_feature(condition=None, library=None, weblog_variant=None, reason=None, force_skip: bool = False):
"""decorator, allow to mark a test function/class as missing"""
skip = _should_skip(library=library, weblog_variant=weblog_variant, condition=condition)
return partial(decorator, skip, force_skip, condition, "missing_feature", reason)
expected_to_fail = _expected_to_fail(library=library, weblog_variant=weblog_variant, condition=condition)
return partial(decorator, expected_to_fail, force_skip, condition, "missing_feature", reason)


def incomplete_test_app(condition=None, library=None, weblog_variant=None, reason=None):
"""Decorator, allow to mark a test function/class as not compatible with the tested application"""
skip = _should_skip(library=library, weblog_variant=weblog_variant, condition=condition)
noxfail = False
return partial(decorator, skip, noxfail, condition, "incomplete_test_app", reason)
expected_to_fail = _expected_to_fail(library=library, weblog_variant=weblog_variant, condition=condition)
skip_test = False
return partial(decorator, expected_to_fail, skip_test, condition, "incomplete_test_app", reason)


def irrelevant(condition=None, library=None, weblog_variant=None, reason=None):
"""decorator, allow to mark a test function/class as not relevant"""
skip = _should_skip(library=library, weblog_variant=weblog_variant, condition=condition)
noxfail = True
return partial(decorator, skip, noxfail, condition, "irrelevant", reason)
expected_to_fail = _expected_to_fail(library=library, weblog_variant=weblog_variant, condition=condition)
skip_test = True
return partial(decorator, expected_to_fail, skip_test, condition, "irrelevant", reason)


def bug(condition=None, library=None, weblog_variant=None, reason=None, force_skip: bool = False):
"""
Decorator, allow to mark a test function/class as an known bug.
The test is executed, and if it passes, and warning is reported
"""

expected_to_fail = _should_skip(library=library, weblog_variant=weblog_variant, condition=condition)
expected_to_fail = _expected_to_fail(library=library, weblog_variant=weblog_variant, condition=condition)
return partial(decorator, expected_to_fail, force_skip, condition, "bug", reason)


def flaky(condition=None, library=None, weblog_variant=None, reason=None):
"""Decorator, allow to mark a test function/class as a known bug, and skip it"""

skip = _should_skip(library=library, weblog_variant=weblog_variant, condition=condition)
noxfail = True
return partial(decorator, skip, noxfail, condition, "flaky", reason)
expected_to_fail = _expected_to_fail(library=library, weblog_variant=weblog_variant, condition=condition)
skip_test = True
return partial(decorator, expected_to_fail, skip_test, condition, "flaky", reason)


def released(
Expand Down Expand Up @@ -223,16 +221,16 @@ def compute_declaration(only_for_library, component_name, declaration, tested_ve
for reason in skip_reasons:
if reason.startswith("flaky"):
_ensure_jira_ticket_as_reason(test_class, reason[7:-1])
return _get_expected_failure_item(test_class, reason, noxfail=True)
return _get_expected_failure_item(test_class, reason, skip_test=True)

if reason.startswith("irrelevant"):
return _get_expected_failure_item(test_class, reason, noxfail=True)
return _get_expected_failure_item(test_class, reason, skip_test=True)

# Otherwise, it's either bug, or missing_feature. Take the first one
if reason.startswith("bug"):
_ensure_jira_ticket_as_reason(test_class, reason[5:-1])

return _get_expected_failure_item(test_class, reason, noxfail=False)
return _get_expected_failure_item(test_class, reason, skip_test=False)

return test_class

Expand Down

0 comments on commit 7f88031

Please sign in to comment.