Bird
0
0

Find the problem in this test:

medium📝 Debug Q7 of 15
PyTest - Writing Assertions
Find the problem in this test:
def test_compare():
    assert pytest.approx(5.0) == 5.0
ATest will fail because 5.0 != pytest.approx(5.0)
Bpytest.approx cannot be used on left side of == operator
CArguments are reversed; actual value should be on left
DNo problem; test will pass
Step-by-Step Solution
Solution:
  1. Step 1: Recall pytest.approx usage

    The actual value should be on the left side of ==, and pytest.approx(expected) on the right.
  2. Step 2: Analyze the assertion

    Here, pytest.approx is on the left, which is not the recommended usage and can cause confusion or errors.
  3. Final Answer:

    Arguments are reversed; actual value should be on left -> Option C
  4. Quick Check:

    Actual == pytest.approx(expected) is correct order [OK]
Quick Trick: Put actual value left, pytest.approx(expected) right [OK]
Common Mistakes:
MISTAKES
  • Swapping actual and expected in assertion
  • Assuming pytest.approx works both sides
  • Ignoring assertion best practices

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes