Bird
0
0

Identify the error in this test code:

medium📝 Debug Q6 of 15
PyTest - Writing Assertions
Identify the error in this test code:
def test_approx():
    value = 2.5
    assert value == approx(2.5)
ASyntax error due to missing parentheses
Bapprox is not imported, causing NameError
CIncorrect use of assert statement
DNo error, test will pass
Step-by-Step Solution
Solution:
  1. Step 1: Check if approx is imported

    The code uses approx without importing it from pytest, so approx is undefined.
  2. Step 2: Understand error type

    This causes a NameError at runtime.
  3. Final Answer:

    approx is not imported, causing NameError -> Option B
  4. Quick Check:

    Using approx without import = NameError [OK]
Quick Trick: Always import approx before using it [OK]
Common Mistakes:
MISTAKES
  • Forgetting to import approx
  • Assuming approx is built-in
  • Misreading error as syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes