Challenge - 5 Problems
Pytest Skip Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a skipped test with reason
What will be the output when running this pytest code snippet?
PyTest
import pytest @pytest.mark.skip(reason="Not implemented yet") def test_feature(): assert 1 == 1 if __name__ == "__main__": import pytest pytest.main([__file__])
Attempts:
2 left
💡 Hint
Look at what @pytest.mark.skip does and how the reason parameter affects the test report.
✗ Incorrect
The @pytest.mark.skip decorator prevents the test from running and marks it as skipped. The reason string is shown in the test report to explain why the test was skipped.
❓ assertion
intermediate2:00remaining
Assertion behavior in skipped tests
If a test is decorated with @pytest.mark.skip(reason="Skip this test"), what happens to assertions inside that test?
PyTest
import pytest @pytest.mark.skip(reason="Skip this test") def test_example(): assert False if __name__ == "__main__": import pytest pytest.main([__file__])
Attempts:
2 left
💡 Hint
Think about whether skipped tests run their code or not.
✗ Incorrect
When a test is skipped, pytest does not execute the test function body, so assertions inside are not run.
🔧 Debug
advanced2:00remaining
Skip decorator with positional reason
What will happen when running this pytest code?
PyTest
import pytest @pytest.mark.skip("Missing reason keyword argument") def test_bug(): assert True if __name__ == "__main__": import pytest pytest.main([__file__])
Attempts:
2 left
💡 Hint
Check how the skip decorator handles positional arguments for the reason.
✗ Incorrect
@pytest.mark.skip accepts the reason as a positional or keyword argument. The positional string is used as the skip reason, and the test is skipped.
🧠 Conceptual
advanced2:00remaining
Difference between @pytest.mark.skip and @pytest.mark.skipif with reason
Which statement correctly describes the difference between @pytest.mark.skip(reason=...) and @pytest.mark.skipif(condition, reason=...) decorators?
Attempts:
2 left
💡 Hint
Think about when each decorator causes skipping.
✗ Incorrect
@pytest.mark.skip always skips the test regardless of any condition. @pytest.mark.skipif skips the test only if the given condition evaluates to True.
❓ framework
expert3:00remaining
Using @pytest.mark.skip with fixtures and reason
Given this pytest code, what will be the test outcome and output reason?
PyTest
import pytest @pytest.fixture def data(): return 42 @pytest.mark.skip(reason="Fixture not ready") def test_data(data): assert data == 42 if __name__ == "__main__": import pytest pytest.main([__file__])
Attempts:
2 left
💡 Hint
Consider if fixtures run when a test is skipped.
✗ Incorrect
When a test is skipped using @pytest.mark.skip, the test function and its fixtures are not executed. The skip reason is shown in the test report.