Skip to content

Commit

Permalink
Refactor to ResultInterpret
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhoyer committed Sep 30, 2024
1 parent ea54015 commit 284f2d2
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 29 deletions.
4 changes: 2 additions & 2 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ backed by :ref:`prepare/feature</plugins/prepare/feature>` plugin.

+A new ``check-result`` key has been added to the test specification. This key
+allows users to configure whether "check" failure will affect the test result.
+The key accepts two options: 'respect' (default) and 'ignore'. When set to
+The key accepts two options: 'respect' (default) and 'skip'. When set to
+'respect', check failures will affect the test result as before. When set to
+'ignore', check failures will not affect the overall test result.
+'skip', check failures will not affect the overall test result.


tmt-1.36.1
Expand Down
4 changes: 2 additions & 2 deletions spec/tests/result.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ description: |

respect
check results are respected (test fails if any check fails) - default value
ignore
skip
check results are ignored (test result is not affected by check failures)

.. versionadded:: 1.37
Expand All @@ -53,7 +53,7 @@ example:

- |
# Ignore check failures
check-result: ignore
check-result: skip

link:
- implemented-by: /tmt/base.py
Expand Down
14 changes: 7 additions & 7 deletions tests/execute/result/check_results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ rlJournalStart
rlAssertGrep "fail dmesg (after-test check)" $rlRun_LOG
rlAssertGrep "check failed" $rlRun_LOG

rlRun -s "tmt run --id \${run} --scratch provision --how local test --name /test/check-fail-ignore execute -vv report -vv 2>&1 >/dev/null" 0
rlAssertGrep "pass /test/check-fail-ignore" $rlRun_LOG
rlRun -s "tmt run --id \${run} --scratch provision --how local test --name /test/check-fail-skip execute -vv report -vv 2>&1 >/dev/null" 0
rlAssertGrep "pass /test/check-fail-skip" $rlRun_LOG
rlAssertGrep "pass dmesg (before-test check)" $rlRun_LOG
rlAssertGrep "fail dmesg (after-test check)" $rlRun_LOG
rlAssertNotGrep "check failed" $rlRun_LOG

rlRun -s "tmt run --id \${run} --scratch provision --how local test --name /test/check-ignore execute -vv report -vv 2>&1 >/dev/null" 0
rlAssertGrep "pass /test/check-ignore" $rlRun_LOG
rlRun -s "tmt run --id \${run} --scratch provision --how local test --name /test/check-skip execute -vv report -vv 2>&1 >/dev/null" 0
rlAssertGrep "pass /test/check-skip" $rlRun_LOG
rlAssertGrep "pass dmesg (before-test check)" $rlRun_LOG
rlAssertGrep "fail dmesg (after-test check)" $rlRun_LOG
rlAssertNotGrep "check failed" $rlRun_LOG
Expand Down Expand Up @@ -65,7 +65,7 @@ rlJournalStart
rlAssertGrep "check_result: respect" $rlRun_LOG

rlRun -s "yq e '.[2]' $results_file"
rlAssertGrep "name: /test/check-fail-ignore" $rlRun_LOG
rlAssertGrep "name: /test/check-fail-skip" $rlRun_LOG
rlAssertGrep "result: pass" $rlRun_LOG
rlAssertNotGrep "note: check failed" $rlRun_LOG
rlAssertGrep "check:" $rlRun_LOG
Expand All @@ -75,10 +75,10 @@ rlJournalStart
rlAssertGrep "- name: dmesg" $rlRun_LOG
rlAssertGrep " result: fail" $rlRun_LOG
rlAssertGrep " event: after-test" $rlRun_LOG
rlAssertGrep "check_result: ignore" $rlRun_LOG
rlAssertGrep "check_result: skip" $rlRun_LOG

rlRun -s "yq e '.[3]' $results_file"
rlAssertGrep "name: /test/check-ignore" $rlRun_LOG
rlAssertGrep "name: /test/check-skip" $rlRun_LOG
rlAssertGrep "result: pass" $rlRun_LOG
rlAssertNotGrep "note: check failed" $rlRun_LOG
rlAssertGrep "check:" $rlRun_LOG
Expand Down
8 changes: 4 additions & 4 deletions tests/execute/result/check_results/main.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ description: Verify that check results, including after-test checks, are correct
check-result: respect
# Expected outcome: FAIL (test passes, but check fails and is respected)

/test/check-fail-ignore:
summary: Test with failing dmesg check (ignore)
/test/check-fail-skip:
summary: Test with failing dmesg check (skip)
test: |
echo "Test passed"
echo "Call Trace:" >> /dev/kmsg
framework: shell
duration: 1m
check:
- how: dmesg
check-result: ignore
check-result: skip
# Expected outcome: PASS (test passes, check fails but is ignored)

/test/check-ignore:
/test/check-skip:
summary: Test with failing dmesg check but ignored due to result interpretation
test: |
echo "Test passed"
Expand Down
3 changes: 3 additions & 0 deletions tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,9 @@ def show(self) -> None:
[check.to_spec() for check in cast(list[Check], value)]
))
continue
if key == 'check_result':
echo(tmt.utils.format(key, value))
continue
if value not in [None, [], {}]:
echo(tmt.utils.format(key, value))
if self.verbosity_level:
Expand Down
26 changes: 13 additions & 13 deletions tmt/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,6 @@ class Result(BaseResult):
serialize=lambda path: None if path is None else str(path),
unserialize=lambda value: None if value is None else Path(value)
)
check_result: str = field(
default='respect',
serialize=lambda value: value,
unserialize=lambda value: value
)

@classmethod
def from_test_invocation(
Expand Down Expand Up @@ -286,8 +281,6 @@ def from_test_invocation(
default_ids.update(ids)
ids = default_ids

check_result = cast(str, invocation.test.node.get('check-result', 'respect'))

_result = Result(
name=invocation.test.name,
serial_number=invocation.test.serial_number,
Expand All @@ -302,23 +295,30 @@ def from_test_invocation(
log=log or [],
guest=ResultGuestData.from_test_invocation(invocation=invocation),
data_path=invocation.relative_test_data_path,
check_result=check_result,
check=invocation.check_results)

for check in _result.check:
print(f" - Name: {check.name}, Result: {check.result}, Event: {check.event}")

return _result.interpret_result(ResultInterpret(
invocation.test.result) if invocation.test.result else ResultInterpret.RESPECT)

def interpret_result(self, interpret: ResultInterpret) -> 'Result':
return _result.interpret_result(
ResultInterpret(invocation.test.result)
if invocation.test.result else ResultInterpret.RESPECT,
ResultInterpret(invocation.test.check_result)
if invocation.test.check_result else ResultInterpret.RESPECT
)

def interpret_result(
self,
interpret: ResultInterpret,
check_interpret: ResultInterpret) -> 'Result':
"""
Interpret result according to a given interpretation instruction.
Inspect and possibly modify :py:attr:`result` and :py:attr:`note`
attributes, following the ``interpret`` value.
:param interpret: how to interpret current result.
:param check_interpret: how to interpret check results.
:returns: :py:class:`Result` instance containing the updated result.
"""

Expand All @@ -329,7 +329,7 @@ def interpret_result(self, interpret: ResultInterpret) -> 'Result':
checks_failed = any(check.result == ResultOutcome.FAIL for check in self.check)

if interpret == ResultInterpret.RESPECT:
if self.check_result == 'respect' and checks_failed:
if check_interpret == ResultInterpret.RESPECT and checks_failed:
self.result = ResultOutcome.FAIL
if self.note:
self.note += ', check failed'
Expand Down
2 changes: 1 addition & 1 deletion tmt/schemas/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ properties:
type: string
enum:
- respect
- ignore
- skip
default: respect

# https://tmt.readthedocs.io/en/stable/spec/core.html#id
Expand Down

0 comments on commit 284f2d2

Please sign in to comment.