Bird
0
0

What will happen when this pytest code runs?

medium📝 Predict Output Q5 of 15
PyTest - Writing Assertions
What will happen when this pytest code runs?
fruits = ['mango', 'orange', 'grape']
assert 'apple' not in fruits
ATest fails with AssertionError
BTest passes
CSyntax error
DRuntime error
Step-by-Step Solution
Solution:
  1. Step 1: Check if 'apple' is not in the list

    'apple' is not in the list fruits, so the condition 'apple' not in fruits is True.
  2. Step 2: Understand assertion result

    Since the condition is True, the assertion passes and no error occurs.
  3. Final Answer:

    Test passes -> Option B
  4. Quick Check:

    Element absent = assertion passes [OK]
Quick Trick: Assert passes if element is not in collection [OK]
Common Mistakes:
MISTAKES
  • Assuming assertion fails when element is absent
  • Confusing 'not in' with 'in'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes