Bird
0
0

Consider the following test code:

medium📝 Predict Output Q5 of 15
PyTest - Markers
Consider the following test code:
import sys
import pytest

@pytest.mark.skipif(sys.platform != 'darwin', reason='Only runs on macOS')
def test_mac_only():
    assert True

What will happen when this test runs on a Windows machine?
AThe test will fail due to platform mismatch
BThe test will run and pass
CThe test will be skipped with the given reason
DPytest will raise a syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Check the condition

    The condition sys.platform != 'darwin' will be True on Windows.
  2. Step 2: Effect of skipif

    Since the condition is True, pytest will skip the test.
  3. Final Answer:

    The test will be skipped with the given reason -> Option C
  4. Quick Check:

    Platform not macOS means skip test [OK]
Quick Trick: Skip if platform is not macOS [OK]
Common Mistakes:
MISTAKES
  • Assuming test runs on all platforms
  • Confusing platform strings
  • Ignoring the skipif condition logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes