Bird
0
0

Given the code below, what will pytest report when running these tests?

medium📝 Predict Output Q13 of 15
PyTest - Test Organization
Given the code below, what will pytest report when running these tests?
class TestMath:
    def test_add(self):
        assert 1 + 1 == 2

    def test_subtract(self):
        assert 5 - 3 == 1
A1 test passed, 1 test failed
B2 tests passed
C2 tests failed
DSyntax error, tests won't run
Step-by-Step Solution
Solution:
  1. Step 1: Check each assertion

    test_add asserts 1+1==2 which is True; test_subtract asserts 5-3==1 which is False.
  2. Step 2: Determine test results

    One test passes (test_add), one test fails (test_subtract).
  3. Final Answer:

    1 test passed, 1 test failed -> Option A
  4. Quick Check:

    Assertions true/false = 1 pass, 1 fail [OK]
Quick Trick: Check each assertion result carefully [OK]
Common Mistakes:
MISTAKES
  • Assuming both tests pass without checking assertions
  • Ignoring that 5 - 3 != 1
  • Thinking syntax error due to indentation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes