Bird
0
0

What will be the result of running this PyTest test code?

medium📝 Predict Output Q13 of 15
PyTest - Writing Assertions
What will be the result of running this PyTest test code?
def test_example():
    x = 5
    y = 10
    assert x + y == 15
    assert y - x == 4
ATest fails on the second assert
BTest fails on the first assert
CSyntax error stops the test
DTest passes without errors
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the first assert statement

    x + y == 15 means 5 + 10 == 15, which is true, so the first assert passes.
  2. Step 2: Evaluate the second assert statement

    y - x == 4 means 10 - 5 == 4, which is false (10 - 5 = 5), so the second assert fails and stops the test.
  3. Final Answer:

    Test fails on the second assert -> Option A
  4. Quick Check:

    5 + 10 = 15 true, 10 - 5 = 5 false [OK]
Quick Trick: Check each assert condition carefully for true/false [OK]
Common Mistakes:
MISTAKES
  • Assuming all asserts pass without checking values
  • Confusing addition and subtraction results
  • Thinking test stops only after all asserts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes