Bird
0
0

Identify the error in this pytest assertion:

medium📝 Debug Q6 of 15
PyTest - Writing Assertions
Identify the error in this pytest assertion:
colors = ['red', 'blue', 'green']
assert 'yellow' not colors
AIncorrect quotes around 'yellow'
BMissing 'in' keyword after 'not'
CWrong list name
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the assertion syntax

    The assertion uses assert 'yellow' not colors, which is missing the keyword in after not.
  2. Step 2: Correct the syntax

    The correct syntax is assert 'yellow' not in colors.
  3. Final Answer:

    Missing 'in' keyword after 'not' -> Option B
  4. Quick Check:

    Correct syntax requires 'not in' [OK]
Quick Trick: Use 'not in' together, never separate [OK]
Common Mistakes:
MISTAKES
  • Omitting 'in' after 'not'
  • Using 'not' alone for membership
  • Syntax errors in assertion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes