Test Overview
This test uses @pytest.mark.xfail to mark a test that is expected to fail. It verifies that the test fails as expected without causing the whole test suite to fail.
This test uses @pytest.mark.xfail to mark a test that is expected to fail. It verifies that the test fails as expected without causing the whole test suite to fail.
import pytest @pytest.mark.xfail(reason="Known bug: division by zero") def test_divide_by_zero(): result = 10 / 0 assert result == 0
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | PyTest test runner initializes and loads test_divide_by_zero | - | PASS |
| 2 | Test function test_divide_by_zero is called | Inside test_divide_by_zero function | - | PASS |
| 3 | Code executes division 10 / 0 causing ZeroDivisionError | Exception ZeroDivisionError raised | - | FAIL |
| 4 | PyTest recognizes test is marked xfail and failure is expected | Test marked as expected failure | Test failure matches expected failure condition | PASS |
| 5 | Test suite continues without marking overall run as failed | Test suite summary shows xfail for this test | Test suite reports test as xfailed, not failed | PASS |