Recall & Review
beginner
What does
@pytest.mark.skip do in a test?It tells pytest to skip running the test function it decorates. The test will be ignored during test execution.
Click to reveal answer
beginner
How do you provide a reason for skipping a test with
@pytest.mark.skip?You add a
reason argument like @pytest.mark.skip(reason='Not ready yet'). This shows why the test was skipped in the test report.Click to reveal answer
beginner
Write a simple example of skipping a test with a reason using
@pytest.mark.skip.import pytest
@pytest.mark.skip(reason='Feature not implemented')
def test_feature():
assert False
Click to reveal answer
beginner
What will the test report show when a test is skipped with a reason?
The test report will mark the test as skipped and display the reason given in the
@pytest.mark.skip(reason='...') decorator.Click to reveal answer
intermediate
Can
@pytest.mark.skip be used conditionally? If not, what is the alternative?No,
@pytest.mark.skip always skips the test. To skip conditionally, use @pytest.mark.skipif(condition, reason='...').Click to reveal answer
What happens when you run a test decorated with
@pytest.mark.skip(reason='Not ready')?✗ Incorrect
Using
@pytest.mark.skip skips the test and shows the reason in the test report.Which of these is the correct way to skip a test with a reason?
✗ Incorrect
The correct syntax is
@pytest.mark.skip(reason='...').If you want to skip a test only on Windows OS, which decorator should you use?
✗ Incorrect
Use
@pytest.mark.skipif(condition, reason='...') to skip conditionally.What is the difference between
@pytest.mark.skip and @pytest.mark.skipif?✗ Incorrect
@pytest.mark.skip always skips; @pytest.mark.skipif skips only if the condition is true.What will happen if you forget to provide a reason in
@pytest.mark.skip?✗ Incorrect
The test is skipped but no reason is shown if you omit the reason argument.
Explain how to skip a test in pytest and provide a reason for skipping.
Think about how to tell pytest not to run a test and why.
You got /4 concepts.
Describe the difference between @pytest.mark.skip and @pytest.mark.skipif and when to use each.
Consider when you want to skip a test unconditionally vs conditionally.
You got /4 concepts.