Bird
0
0

What will be the output when running this pytest code?

medium📝 Predict Output Q4 of 15
PyTest - Basics and Setup
What will be the output when running this pytest code?
def test_sum():
    assert sum([1, 2, 3]) == 6

def test_fail():
    assert 2 + 2 == 5
ABoth tests fail
BBoth tests pass
COne test passes, one test fails
DSyntax error stops tests
Step-by-Step Solution
Solution:
  1. Step 1: Analyze each test assertion

    test_sum asserts sum([1,2,3]) == 6 which is true; test_fail asserts 2+2 == 5 which is false.
  2. Step 2: Determine test results

    First test passes, second test fails; pytest reports one pass and one fail.
  3. Final Answer:

    One test passes, one test fails -> Option C
  4. Quick Check:

    Assertions true/false = pass/fail [OK]
Quick Trick: True assertions pass, false assertions fail [OK]
Common Mistakes:
MISTAKES
  • Assuming both tests pass despite wrong assertion
  • Thinking pytest stops on first failure
  • Confusing syntax errors with assertion failures

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes