Bird
0
0

What is wrong with this pytest test code?

medium📝 Debug Q6 of 15
PyTest - Basics and Setup
What is wrong with this pytest test code?
def test_multiply():
    result = 2 * 3
    assert result == 5
AThe test function name should not start with 'test_'
BThe assertion is incorrect; 2 * 3 equals 6, not 5
CThe multiplication operator '*' is invalid in Python
DThe variable 'result' is not defined before use
Step-by-Step Solution
Solution:
  1. Step 1: Review the test logic

    The code multiplies 2 by 3 and stores it in 'result'.
  2. Step 2: Check the assertion

    The assertion expects 'result' to be 5, but 2 * 3 equals 6.
  3. Step 3: Identify the error

    The assertion is incorrect, causing the test to fail.
  4. Final Answer:

    The assertion is incorrect; 2 * 3 equals 6, not 5 -> Option B
  5. Quick Check:

    Verify expected values in assertions [OK]
Quick Trick: Always verify expected values in assertions [OK]
Common Mistakes:
MISTAKES
  • Incorrect expected value in assert statements
  • Misunderstanding basic operations in tests
  • Assuming test passes without checking logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes