Bird
0
0

Identify the error in this pytest test code:

medium📝 Debug Q6 of 15
PyTest - Basics and Setup
Identify the error in this pytest test code:
def test_divide():
    result = 10 / 0
    assert result == 0
ATest will be skipped automatically
BAssertion is incorrect but test passes
CSyntax error due to missing colon
DDivision by zero causes ZeroDivisionError
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the division operation

    Dividing 10 by 0 causes a ZeroDivisionError exception in Python.
  2. Step 2: Understand pytest behavior on exceptions

    pytest reports the test as error due to unhandled exception, test does not pass.
  3. Final Answer:

    Division by zero causes ZeroDivisionError -> Option D
  4. Quick Check:

    ZeroDivisionError = test error [OK]
Quick Trick: Division by zero raises error, test fails [OK]
Common Mistakes:
MISTAKES
  • Thinking assertion fails but no error
  • Expecting test skip
  • Missing exception understanding

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes