Bird
0
0

Which of the following is the correct syntax to skip a test if Python version is less than 3.8?

easy📝 Syntax Q12 of 15
PyTest - Markers
Which of the following is the correct syntax to skip a test if Python version is less than 3.8?
A@pytest.mark.skipif(sys.version_info < (3, 8), reason='Python < 3.8')
B@pytest.skipif(sys.version_info < (3, 8), reason='Python < 3.8')
C@pytest.mark.skipif(sys.version < 3.8, reason='Python < 3.8')
D@pytest.mark.skipif(sys.version_info <= 3.8, reason='Python < 3.8')
Step-by-Step Solution
Solution:
  1. Step 1: Check correct decorator usage

    The correct decorator is @pytest.mark.skipif, not @pytest.skipif.
  2. Step 2: Verify condition and syntax

    Python version is checked with sys.version_info tuple; comparison uses < (less than) and tuple format (3, 8).
  3. Final Answer:

    @pytest.mark.skipif(sys.version_info < (3, 8), reason='Python < 3.8') -> Option A
  4. Quick Check:

    Correct decorator and version tuple [OK]
Quick Trick: Use sys.version_info tuple with @pytest.mark.skipif [OK]
Common Mistakes:
MISTAKES
  • Using @pytest.skipif instead of @pytest.mark.skipif
  • Comparing sys.version instead of sys.version_info
  • Using <= instead of < for version check

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes