Bird
0
0

Which of the following conditions correctly skips a test only on Windows OS using @pytest.mark.skipif?

easy🧠 Conceptual Q2 of 15
PyTest - Markers
Which of the following conditions correctly skips a test only on Windows OS using @pytest.mark.skipif?
Askipif(sys.platform == 'darwin', reason='Skip on Windows')
Bskipif(sys.platform != 'win32', reason='Skip on Windows')
Cskipif(sys.platform == 'linux', reason='Skip on Windows')
Dskipif(sys.platform == 'win32', reason='Skip on Windows')
Step-by-Step Solution
Solution:
  1. Step 1: Identify the platform string for Windows

    In Python, sys.platform returns 'win32' on Windows systems.
  2. Step 2: Use the condition to skip only on Windows

    The condition sys.platform == 'win32' is True only on Windows, so the test is skipped there.
  3. Final Answer:

    skipif(sys.platform == 'win32', reason='Skip on Windows') -> Option D
  4. Quick Check:

    Windows platform check = A [OK]
Quick Trick: Use sys.platform=='win32' to detect Windows in skipif [OK]
Common Mistakes:
MISTAKES
  • Using != instead of == for condition
  • Confusing platform names for OS
  • Skipping on wrong OS by mistake

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes