Bird
0
0

Identify the error in this pytest test code:

medium📝 Debug Q14 of 15
PyTest - Basics and Setup
Identify the error in this pytest test code:
def test_sum():
    total = sum([1, 2, 3])
    assert total = 6
AUsing assignment '=' instead of comparison '==' in assert
Bsum() function is not defined
CTest function name does not start with 'test_'
DMissing colon after function definition
Step-by-Step Solution
Solution:
  1. Step 1: Check the assert statement syntax

    The assert statement uses '=' which is assignment, not comparison. It should be '=='.
  2. Step 2: Verify other parts of the code

    sum() is a built-in function, function name is correct, and colon is present.
  3. Final Answer:

    Using assignment '=' instead of comparison '==' in assert -> Option A
  4. Quick Check:

    Assert needs '==' not '=' [OK]
Quick Trick: Assert uses '==' for comparison, not '=' [OK]
Common Mistakes:
MISTAKES
  • Using '=' instead of '==' in assert
  • Confusing function name rules
  • Missing colons in function definitions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes