Bird
0
0

Which of the following is the correct syntax to skip a test only 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 only if Python version is less than 3.8?
A@pytest.mark.skipif(sys.version_info < (3, 8)\ndef test_func(): pass
B@pytest.mark.skipif(sys.version_info < (3, 8), reason='Python < 3.8')\ndef test_func(): pass
C@pytest.mark.skipif(sys.version_info < 3.8)\ndef test_func(): pass
D@pytest.mark.skipif(sys.version_info < '3.8')\ndef test_func(): pass
Step-by-Step Solution
Solution:
  1. Step 1: Check correct version tuple comparison syntax

    Python version info is a tuple like (3, 7, 5). So comparisons must use tuples, e.g., (3, 8).
  2. Step 2: Verify correct use of skipif with reason

    @pytest.mark.skipif(sys.version_info < (3, 8), reason='Python < 3.8')\ndef test_func(): pass uses tuple comparison and includes a reason string, which is best practice for clarity.
  3. Final Answer:

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

    Use tuple and reason in skipif = C [OK]
Quick Trick: Use tuple for version and add reason in skipif [OK]
Common Mistakes:
MISTAKES
  • Using float instead of tuple for version
  • Omitting reason argument
  • Comparing version to string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes