Bird
0
0

Identify the syntax error in this pytest assertion:

medium📝 Debug Q6 of 15
PyTest - Writing Assertions
Identify the syntax error in this pytest assertion:
def test_example():
    x = 10
    assert x == 5 "x must be 5"
AUsing double quotes instead of single quotes
BMissing comma between condition and message
CIncorrect indentation of assert statement
DUsing parentheses around the assert condition
Step-by-Step Solution
Solution:
  1. Step 1: Review assert syntax

    In pytest, to add a message, a comma must separate the condition and the message string.
  2. Step 2: Analyze the code

    The code lacks a comma between x == 5 and "x must be 5".
  3. Final Answer:

    Missing comma between condition and message -> Option B
  4. Quick Check:

    Comma required before message string [OK]
Quick Trick: Comma separates assert condition and message [OK]
Common Mistakes:
MISTAKES
  • Forgetting the comma before the message
  • Misplacing quotes around message
  • Incorrect indentation causing syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes