Skip to content

Commit

Permalink
Adjust tests accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
psss committed Oct 25, 2024
1 parent 3f75c53 commit 45889d7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions tests/execute/result/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rlJournalStart
rlAssertGrep "fail /test/check-fail-respect (check 'dmesg' failed, original test result: pass)" "$rlRun_LOG"
rlAssertGrep "pass /test/check-override (check 'dmesg' failed, test result overridden: pass)" "$rlRun_LOG"
rlAssertGrep "pass /test/check-pass" "$rlRun_LOG"
rlAssertGrep "fail /test/check-pass-test-xfail (test was expected to fail, original test result: pass)" "$rlRun_LOG"
rlAssertGrep "pass /test/check-xfail-fail (check 'dmesg' failed as expected)" "$rlRun_LOG"
rlAssertGrep "fail /test/check-xfail-pass (check 'dmesg' did not fail as expected, original test result: pass)" "$rlRun_LOG"
rlPhaseEnd
Expand Down
10 changes: 10 additions & 0 deletions tests/execute/result/check/test.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ duration: 1m
- how: dmesg
result: respect

/check-pass-test-xfail:
summary: Everything passing but failure expected
description: |
Expected outcome: FAIL (test passes, check passes, but fail is expected)
test: echo "Test passed"
check:
- how: dmesg
result: respect
result: xfail

/check-fail-respect:
summary: Test with failing dmesg check (respect)
description: |
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,14 @@ def test_aggregate_check_results(
ResultInterpret.XFAIL,
{"check1": CheckResultInterpret.RESPECT},
ResultOutcome.PASS,
"original result: fail"
"check 'check1' failed, test failed as expected, original test result: fail"
),
(
ResultOutcome.PASS,
ResultInterpret.XFAIL,
{"check1": CheckResultInterpret.RESPECT},
ResultOutcome.FAIL,
"original result: pass"
"test was expected to fail, original test result: pass"
),
# Test INFO interpretation
Expand All @@ -241,14 +241,14 @@ def test_aggregate_check_results(
ResultInterpret.INFO,
{"check1": CheckResultInterpret.RESPECT},
ResultOutcome.INFO,
"original result: fail"
"check 'check1' failed, test result overridden: info, original test result: fail"
),
(
ResultOutcome.PASS,
ResultInterpret.INFO,
{"check1": CheckResultInterpret.RESPECT},
ResultOutcome.INFO,
"original result: pass"
"test result overridden: info, original test result: pass"
),
# Test WARN interpretation
Expand All @@ -257,7 +257,7 @@ def test_aggregate_check_results(
ResultInterpret.WARN,
{"check1": CheckResultInterpret.RESPECT},
ResultOutcome.WARN,
"original result: pass"
"test result overridden: warn, original test result: pass"
),
# Test ERROR interpretation
Expand All @@ -266,7 +266,7 @@ def test_aggregate_check_results(
ResultInterpret.ERROR,
{"check1": CheckResultInterpret.RESPECT},
ResultOutcome.ERROR,
"original result: pass"
"test result overridden: error, original test result: pass"
),
# Test CUSTOM interpretation (should not modify result)
Expand Down Expand Up @@ -333,7 +333,7 @@ def test_result_interpret_check_phases() -> None:
interpreted = result.interpret_result(ResultInterpret.RESPECT, interpret_checks)
assert interpreted.note is not None
assert "check 'check1' failed" in interpreted.note
assert "check 'check2'" not in interpreted.note # check2 passed
assert "check 'check2' is informational" in interpreted.note

# Verify individual check results were interpreted
assert interpreted.check[0].result == ResultOutcome.PASS # check1 BEFORE_TEST
Expand Down
5 changes: 2 additions & 3 deletions tmt/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ def reduce(outcomes: list['ResultOutcome']) -> 'ResultOutcome':

raise GeneralError("No result outcome found to reduce.")


# Cannot subclass enums :/
# https://docs.python.org/3/library/enum.html#restricted-enum-subclassing


class ResultInterpret(enum.Enum):
# These are "inherited" from ResultOutcome
PASS = 'pass'
Expand Down Expand Up @@ -480,7 +479,7 @@ def interpret_result(
self.result = ResultOutcome.FAIL
self.append_note("test was expected to fail")

if self.result == ResultOutcome.FAIL:
elif self.result == ResultOutcome.FAIL:
self.result = ResultOutcome.PASS
self.append_note("test failed as expected")

Expand Down

0 comments on commit 45889d7

Please sign in to comment.