Expected failures
@karva.tags.expect_fail treats a failing test as a success and a passing
test as a failure.
| test.py | |
|---|---|
1 2 3 4 5 | |
Use @karva.tags.expect_fail or @karva.tags.expect_fail() without a reason.
A reason can also be positional: @karva.tags.expect_fail("Known bug").
The reason is retained in JSON, JSONL, and JUnit reports and explains an
unexpected pass. Expected failures still show PASS and count as passed in
the terminal.
Conditions
Pass boolean conditions to expect failure when any condition is true:
| test.py | |
|---|---|
1 2 3 4 5 6 | |
@karva.tags.expect_fail(False, False) runs as a normal test.
Restricting the expected exception
Use raises= to require a particular exception or a tuple of exception classes.
Subclasses match normally:
| Python | |
|---|---|
1 2 3 | |
A different exception is a normal failure and follows the retry policy. A matching
expected failure is never retried. Without raises=, ordinary test-body exceptions
are accepted. Fixture setup and teardown errors, missing fixtures, framework
timeouts, background exceptions, and non-None return values cannot become
expected failures.
Pytest
@pytest.mark.xfail is also supported:
| test.py | |
|---|---|
1 2 3 4 5 | |