Bird
0
0

What is wrong with this pytest marker usage?

medium📝 Debug Q14 of 15
PyTest - Markers
What is wrong with this pytest marker usage?
@pytest.mark.skipif(sys.platform == 'win32')
def test_func():
    assert True
AMissing import of sys module
BIncorrect marker name 'skipif'
CMissing parentheses after skipif
DCannot use conditions in markers
Step-by-Step Solution
Solution:
  1. Step 1: Check the code for required imports

    The code uses 'sys.platform' but does not import 'sys'.
  2. Step 2: Verify marker syntax

    '@pytest.mark.skipif(condition)' is correct syntax, so no error there.
  3. Final Answer:

    Missing import of sys module -> Option A
  4. Quick Check:

    Use imports for conditions in markers [OK]
Quick Trick: Always import modules used in marker conditions [OK]
Common Mistakes:
MISTAKES
  • Forgetting to import modules like sys
  • Misnaming skipif marker
  • Using skipif without condition parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes