Bird
0
0

Identify the error in this pytest assertion and select the correct fix:

medium📝 Debug Q14 of 15
PyTest - Writing Assertions
Identify the error in this pytest assertion and select the correct fix:
colors = ['red', 'green', 'blue']
assert 'yellow' in colors not
AUse 'assert not 'yellow' in colors' instead
BSyntaxError: 'not' should come before 'in' as 'not in'
CReplace 'in' with 'not in' and remove 'not' at the end
DNo error, assertion is correct
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the assertion syntax

    The expression ends with 'colors not' which is invalid syntax in Python.
  2. Step 2: Correct the membership operator usage

    The correct operator for checking absence is 'not in', written together, not separated.
  3. Final Answer:

    SyntaxError: 'not' should come before 'in' as 'not in' -> Option B
  4. Quick Check:

    Use 'not in' together, no trailing 'not' [OK]
Quick Trick: Write 'not in' together, never split or reorder [OK]
Common Mistakes:
MISTAKES
  • Writing 'in colors not' instead of 'not in colors'
  • Using 'assert colors not in 'yellow'' which reverses order
  • Omitting 'not' or placing it incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes