Bird
0
0

Given this pytest test code, what will be the output when running pytest?

medium📝 Predict Output Q4 of 15
PyTest - Basics and Setup
Given this pytest test code, what will be the output when running pytest?
def test_add():
    assert 2 + 2 == 5
ATest fails with an AssertionError
BTest passes successfully
CSyntax error occurs
DTest is skipped automatically
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the assertion in the test

    The assertion checks if 2 + 2 equals 5, which is false.
  2. Step 2: Understand pytest behavior on failed assertions

    pytest reports a failure with AssertionError when an assert condition is false.
  3. Final Answer:

    Test fails with an AssertionError -> Option A
  4. Quick Check:

    False assert = test failure [OK]
Quick Trick: False assert causes test failure in pytest [OK]
Common Mistakes:
MISTAKES
  • Thinking test passes despite wrong assert
  • Expecting syntax error
  • Assuming test skips automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes