Recall & Review
beginner
What does
@pytest.mark.skipif do in a test?It skips the test if the given condition is true. This helps avoid running tests when certain requirements are not met.
Click to reveal answer
beginner
How do you write a condition to skip a test only on Windows using
@pytest.mark.skipif?Use
sys.platform == 'win32' as the condition. Example: @pytest.mark.skipif(sys.platform == 'win32', reason='Skip on Windows')Click to reveal answer
beginner
Why should you always provide a
reason argument in @pytest.mark.skipif?The
reason explains why the test is skipped. It helps others understand the skip and improves test reports.Click to reveal answer
intermediate
Can
@pytest.mark.skipif condition use variables or expressions?Yes, the condition can be any Python expression that evaluates to True or False, including variables, function calls, or complex logic.
Click to reveal answer
beginner
Example: What happens if you write
@pytest.mark.skipif(True, reason='Always skip') above a test?The test will always be skipped because the condition is always True.
Click to reveal answer
What does
@pytest.mark.skipif(condition, reason='...') do?✗ Incorrect
The decorator skips the test when the condition evaluates to True.
Which of these is a valid condition to skip a test on Python version less than 3.8?
✗ Incorrect
sys.version_info is a tuple; comparing it to (3, 8) checks the Python version.
What happens if you omit the
reason argument in @pytest.mark.skipif?✗ Incorrect
The test is skipped but the report lacks the skip reason, which is not recommended.
Can
@pytest.mark.skipif be used to skip tests based on environment variables?✗ Incorrect
You can use any Python expression, including environment variable checks.
If a test is marked with
@pytest.mark.skipif(False, reason='...'), what happens?✗ Incorrect
The condition is False, so the test runs as usual.
Explain how to use
@pytest.mark.skipif to skip tests conditionally. Include why the reason argument is important.Think about when you want to avoid running a test and how to tell others why.
You got /4 concepts.
Describe a real-life scenario where
@pytest.mark.skipif would be useful in testing.Consider differences in environments or missing dependencies.
You got /3 concepts.