0
0
PyTesttesting~5 mins

@pytest.mark.skip with reason - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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')?
AThe test is skipped and the reason is shown in the report.
BThe test runs but logs the reason.
CThe test fails with the reason as error.
DThe test runs normally without skipping.
Which of these is the correct way to skip a test with a reason?
A@pytest.mark.skip('Bug found')
B@pytest.mark.skipif(reason='Bug found')
C@pytest.skip(reason='Bug found')
D@pytest.mark.skip(reason='Bug found')
If you want to skip a test only on Windows OS, which decorator should you use?
A@pytest.mark.skipif(reason='Windows OS')
B@pytest.mark.skip(reason='Windows OS')
C@pytest.mark.skipif(sys.platform == 'win32', reason='Windows OS')
D@pytest.mark.skipif(True)
What is the difference between @pytest.mark.skip and @pytest.mark.skipif?
ANo difference, both behave the same.
Bskip always skips; skipif skips only if condition is true.
Cskipif always skips; skip skips conditionally.
Dskip runs the test; skipif skips the test.
What will happen if you forget to provide a reason in @pytest.mark.skip?
AThe test will be skipped without a reason shown.
BThe test will run normally.
CPytest will raise an error.
DThe test will fail.
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.