Recall & Review
beginner
What does the pytest marker
@pytest.mark.skip do?It tells pytest to skip the test unconditionally, so the test will not run at all.
Click to reveal answer
beginner
How does
@pytest.mark.skipif(condition) work?It skips the test only if the given condition is true. If false, the test runs normally.
Click to reveal answer
beginner
What is the purpose of
@pytest.mark.xfail?It marks a test as expected to fail. If the test fails, pytest reports it as an expected failure, not a test failure.
Click to reveal answer
intermediate
When would you use
skipif instead of skip?Use
skipif when you want to skip a test only under certain conditions, like missing dependencies or specific OS.Click to reveal answer
intermediate
What happens if a test marked with
xfail passes?Pytest reports it as an unexpected pass, which means the test was expected to fail but did not.
Click to reveal answer
What does
@pytest.mark.skip do?✗ Incorrect
skip skips the test no matter what.
When does
@pytest.mark.skipif(condition) skip a test?✗ Incorrect
skipif skips only when the condition is true.
What does
@pytest.mark.xfail indicate?✗ Incorrect
xfail marks tests expected to fail.
If a test marked with
xfail passes, pytest reports it as:✗ Incorrect
Passing an xfail test is an unexpected pass.
Which marker would you use to skip a test only on Windows OS?
✗ Incorrect
skipif with a condition checks the OS and skips accordingly.
Explain the differences between
skip, skipif, and xfail markers in pytest.Think about when and why you would skip or expect failure.
You got /4 concepts.
Describe a real-life scenario where you would use
@pytest.mark.skipif.Consider tests that depend on external conditions.
You got /3 concepts.