Bird
0
0

Identify the error in this PyTest test function:

medium📝 Debug Q14 of 15
PyTest - Basics and Setup
Identify the error in this PyTest test function:
def test_sum():
    total = 2 + 2
    assert total = 4
AUsing single equals (=) instead of double equals (==) in assert
BFunction name does not start with test_
CMissing return statement in test function
DIndentation error in function body
Step-by-Step Solution
Solution:
  1. Step 1: Check the assert statement syntax

    The assert uses = which is assignment, not comparison. It should be ==.
  2. Step 2: Confirm function name and indentation

    The function name starts with test_ and indentation is correct, so no error there.
  3. Final Answer:

    Using single equals (=) instead of double equals (==) in assert -> Option A
  4. Quick Check:

    Assert needs ==, not = [OK]
Quick Trick: Use == in assert, not = for comparison [OK]
Common Mistakes:
MISTAKES
  • Using = instead of == in assert
  • Thinking return is needed in test functions
  • Confusing indentation errors with syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes