Bird
0
0

Find the bug in this test code:

medium📝 Debug Q7 of 15
PyTest - Markers
Find the bug in this test code:
import pytest
import sys

@pytest.mark.skipif(sys.version_info < (3, 6), reason='Requires 3.6+')
def test_example():
    assert True

@pytest.mark.skipif(sys.version_info < (3, 6), reason='Requires 3.6+')
def test_example():
    assert False
ACondition syntax is invalid
BDuplicate test function names cause one to overwrite the other
CReason string is missing
Dskipif cannot be used twice in same file
Step-by-Step Solution
Solution:
  1. Step 1: Check function names

    Both test functions are named test_example, causing the second to overwrite the first.
  2. Step 2: Understand effect on tests

    Only the second test runs, which asserts False and fails.
  3. Final Answer:

    Duplicate test function names cause one to overwrite the other -> Option B
  4. Quick Check:

    Unique test names prevent overwriting = B [OK]
Quick Trick: Use unique test function names to avoid overwriting [OK]
Common Mistakes:
MISTAKES
  • Using same test function name twice
  • Assuming skipif disallows multiple tests
  • Ignoring overwrite effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes