Expect fail
The expect_fail tag is used to mark a test as expected to fail. When a test marked with expect_fail fails, it is considered a success. When a test marked with expect_fail passes, it is considered a failure.
Basic Usage
| test.py | |
|---|---|
1 2 3 4 5 | |
Then running uv run karva test will result in one passed test.
| test.py | |
|---|---|
1 2 3 4 5 | |
Then running uv run karva test will result in one passed test.
Reason
You can provide a str reason as a positional or keyword argument.
| test.py | |
|---|---|
1 2 3 4 5 | |
Then running uv run karva test will result in one passed test.
| test.py | |
|---|---|
1 2 3 4 5 | |
Then running uv run karva test will result in one passed test.
The reason only shows when the test passes when expected to fail.
| test.py | |
|---|---|
1 2 3 4 5 | |
Then running uv run karva test will result in one failed test.
Pytest
We can also still use @pytest.mark.xfail.
| test.py | |
|---|---|
1 2 3 4 5 | |
Then running uv run karva test will result in one passed test.
Conditions
We can provide bool conditions as a positional arguments.
Then the test will only be expected to fail if all conditions are True.
| test.py | |
|---|---|
1 2 3 4 5 | |
Then running uv run karva test will result in one passed test.
You can still provide a reason as a keyword argument.
| test.py | |
|---|---|
1 2 3 4 5 | |
Then running uv run karva test will result in one passed test.
Multiple Conditions
| test.py | |
|---|---|
1 2 3 4 5 | |
Then running uv run karva test will result in one failed test.