Bird
0
0

Given the code below, what will happen when running the test on a Windows system?

medium📝 Predict Output Q13 of 15
PyTest - Markers
Given the code below, what will happen when running the test on a Windows system?
import sys
import pytest

@pytest.mark.skipif(sys.platform != 'win32', reason='Only runs on Windows')
def test_windows_feature():
    assert True
AThe test will raise a syntax error
BThe test will always run regardless of platform
CThe test will fail on Windows systems
DThe test will be skipped on non-Windows systems
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the skip condition

    The condition sys.platform != 'win32' means skip if platform is not Windows.
  2. Step 2: Determine behavior on Windows

    On Windows, sys.platform == 'win32', so condition is False, test runs. On other OS, condition True, test skipped.
  3. Final Answer:

    The test will be skipped on non-Windows systems -> Option D
  4. Quick Check:

    Skip if not Windows [OK]
Quick Trick: Condition True means skip; False means run test [OK]
Common Mistakes:
MISTAKES
  • Thinking test runs only on non-Windows
  • Confusing != with == in condition
  • Assuming syntax error from decorator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes