0
0
PyTesttesting~5 mins

Built-in markers (skip, skipif, xfail) in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ARuns the test only if a condition is true
BMarks the test as expected to fail
CSkips the test unconditionally
DRuns the test twice
When does @pytest.mark.skipif(condition) skip a test?
AOnly if the condition is true
BNever
COnly if the condition is false
DAlways
What does @pytest.mark.xfail indicate?
ATest should be skipped
BTest is expected to fail
CTest must pass twice
DTest is flaky
If a test marked with xfail passes, pytest reports it as:
ASkipped
BFail
CPass
DUnexpected pass
Which marker would you use to skip a test only on Windows OS?
A@pytest.mark.skipif(sys.platform == 'win32')
B@pytest.mark.xfail
C@pytest.mark.skip
D@pytest.mark.run
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.