Bird
0
0

What will be the output when running this pytest test code?

medium📝 Predict Output Q13 of 15
PyTest - Basics and Setup
What will be the output when running this pytest test code?
def test_example():
    x = 5
    y = 2
    assert x - y == 3
ATest passes successfully
BTest fails with AssertionError
CSyntaxError occurs
DTest is skipped automatically
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the assertion expression

    The expression 5 - 2 == 3 is true, so the assertion passes.
  2. Step 2: Understand PyTest test result

    Since the assertion is true, PyTest will mark the test as passed without errors.
  3. Final Answer:

    Test passes successfully -> Option A
  4. Quick Check:

    5 - 2 == 3 is True [OK]
Quick Trick: Check if assertion condition is true to predict pass/fail [OK]
Common Mistakes:
MISTAKES
  • Assuming assertion fails when it is true
  • Confusing syntax errors with assertion errors
  • Thinking tests skip without skip decorators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes