Bird
0
0

Which of the following is the correct syntax to add a message to an assert statement in pytest?

easy📝 assertion Q12 of 15
PyTest - Writing Assertions
Which of the following is the correct syntax to add a message to an assert statement in pytest?
Aassert(x == 5) : "x should be 5"
Bassert x == 5, "x should be 5"
Cassert x == 5 then "x should be 5"
Dassert x == 5 => "x should be 5"
Step-by-Step Solution
Solution:
  1. Step 1: Recall Python assert syntax

    Python assert statements use a comma to separate the condition and the message: assert condition, message.
  2. Step 2: Match with pytest usage

    pytest uses the same syntax, so assert x == 5, "x should be 5" is correct.
  3. Final Answer:

    assert x == 5, "x should be 5" -> Option B
  4. Quick Check:

    Assert syntax uses comma for message [OK]
Quick Trick: Use comma after condition for assert message [OK]
Common Mistakes:
MISTAKES
  • Using colon or arrow instead of comma
  • Adding message without comma
  • Using parentheses incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes