Bird
0
0

Identify the error in this pytest code snippet:

medium📝 Debug Q14 of 15
PyTest - Markers
Identify the error in this pytest code snippet:
import pytest

@pytest.mark.skipif(sys.platform == 'win32')
def test_func():
    assert True
AMissing import of sys module causes NameError.
Bskipif should be skip to always skip the test.
CThe condition syntax is incorrect; should use double equals.
DThe test function must return a value.
Step-by-Step Solution
Solution:
  1. Step 1: Check imports used in condition

    The condition uses sys.platform, but sys is not imported, causing a NameError at runtime.
  2. Step 2: Verify other parts

    The condition syntax is correct with ==, skipif is valid, and test functions do not need to return values.
  3. Final Answer:

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

    Missing import sys = A [OK]
Quick Trick: Always import modules used in skipif conditions [OK]
Common Mistakes:
MISTAKES
  • Forgetting to import sys
  • Confusing skipif with skip
  • Expecting test functions to return values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes