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:
def test_values():
    a = 3
    b = 4
    assert a = b
AVariables a and b are not defined
BIncorrect indentation
CMissing colon after function definition
DUsing '=' instead of '==' in assertion
Step-by-Step Solution
Solution:
  1. Step 1: Check assertion syntax

    The assertion uses a single '=' which is assignment, not comparison.
  2. Step 2: Correct syntax for equality check

    Use '==' to compare values in assertions, so it should be 'assert a == b'.
  3. Final Answer:

    Using '=' instead of '==' in assertion -> Option D
  4. Quick Check:

    Equality requires '==' not '=' [OK]
Quick Trick: Use '==' for comparison, '=' is assignment [OK]
Common Mistakes:
MISTAKES
  • Using '=' in assert
  • Confusing assignment with comparison
  • Ignoring syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes