Overview - @pytest.mark.xfail for expected failures
What is it?
@pytest.mark.xfail is a special marker in pytest, a Python testing tool. It tells pytest that a test is expected to fail because of a known issue or bug. When pytest runs such a test, it does not count the failure as a problem but as an expected outcome. This helps keep test reports clear and focused on unexpected problems.
Why it matters
Without @pytest.mark.xfail, tests that are known to fail would clutter test results with failures, making it hard to spot new or unexpected bugs. It helps teams track known issues without breaking the whole test suite. This way, developers can focus on fixing new problems while still being reminded of existing ones.
Where it fits
Before learning @pytest.mark.xfail, you should understand basic pytest test writing and assertions. After this, you can learn about pytest fixtures, parameterized tests, and advanced test reporting techniques.