0
0
PyTesttesting~20 mins

Built-in markers (skip, skipif, xfail) in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Built-in Markers Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of pytest with skip marker
What will be the test execution result when running this pytest code?
PyTest
import pytest

@pytest.mark.skip(reason="Not ready yet")
def test_example():
    assert 1 == 1
AThe test is skipped and reported as skipped.
BThe test runs and passes.
CThe test runs and fails.
DSyntaxError occurs due to incorrect marker usage.
Attempts:
2 left
💡 Hint
The skip marker tells pytest not to run the test but to mark it as skipped.
Predict Output
intermediate
2:00remaining
Behavior of skipif marker with condition
What will pytest report when running this test on a Linux system?
PyTest
import pytest
import sys

@pytest.mark.skipif(sys.platform != 'linux', reason='Only runs on Linux')
def test_linux_only():
    assert True
ATest always runs and passes regardless of OS.
BTest runs and passes on Linux; skipped on other OS.
CTest always skipped regardless of OS.
DTest fails with ImportError.
Attempts:
2 left
💡 Hint
skipif skips the test only if the condition is True.
assertion
advanced
2:00remaining
Assertion outcome with xfail marker
Given this pytest test marked with xfail, what is the final test report status if the assertion fails?
PyTest
import pytest

@pytest.mark.xfail(reason='Known bug')
def test_buggy():
    assert 1 == 2
ATest is skipped.
BTest is reported as failed.
CTest is reported as passed.
DTest is reported as xfailed (expected failure).
Attempts:
2 left
💡 Hint
xfail marks tests expected to fail without failing the suite.
Predict Output
advanced
2:00remaining
xfail with passing test behavior
What will pytest report if a test marked with xfail actually passes?
PyTest
import pytest

@pytest.mark.xfail(reason='Known bug')
def test_fixed():
    assert 2 == 2
ATest is reported as xpassed (unexpected pass).
BTest is reported as failed.
CTest is reported as passed.
DTest is skipped.
Attempts:
2 left
💡 Hint
xfail expects failure; passing is unexpected.
🔧 Debug
expert
2:00remaining
Identify the error in skipif usage
Which option correctly identifies the error in this pytest code snippet?
PyTest
import pytest
import sys

@pytest.mark.skipif(sys.platform == "win32", reason='Skip on Windows')
def test_func():
    assert True
AThe condition is a string and should be a boolean expression, causing the test to always skip.
BThe reason parameter is missing, causing a TypeError.
CThere is no error; the code runs and skips on Windows.
DThe skipif marker is used incorrectly; it should be skip instead.
Attempts:
2 left
💡 Hint
skipif expects a boolean condition, not a string.