Bird
0
0

Identify the error in this test code snippet:

medium📝 Debug Q14 of 15
PyTest - Writing Assertions
Identify the error in this test code snippet:
def test_approx():
    result = 1.0001
    assert result == pytest.approx(1.0, rel=0.00001)
AThe relative tolerance is too small, causing test to fail
Bpytest.approx does not accept rel parameter
CThe assertion syntax is incorrect
DThe variable result should be an integer
Step-by-Step Solution
Solution:
  1. Step 1: Check relative tolerance meaning

    rel=0.00001 means allowed difference is 0.00001 * 1.0 = 0.00001.
  2. Step 2: Compare actual difference with tolerance

    Difference is 0.0001, which is greater than 0.00001, so assertion fails.
  3. Final Answer:

    The relative tolerance is too small, causing test to fail -> Option A
  4. Quick Check:

    Difference > rel tolerance causes failure [OK]
Quick Trick: Check if difference fits within rel tolerance [OK]
Common Mistakes:
MISTAKES
  • Assuming rel parameter is invalid
  • Ignoring difference size vs tolerance
  • Confusing syntax error with logic error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes