Bird
0
0

What will be the output when running this pytest code?

medium📝 Predict Output Q13 of 15
PyTest - Writing Assertions
What will be the output when running this pytest code?
def test_value():
    x = 3
    assert x == 5, "x is not equal to 5"
ATest passes silently
BTest skipped automatically
CSyntaxError due to assert message
DTest fails with message: x is not equal to 5
Step-by-Step Solution
Solution:
  1. Step 1: Check the assertion condition

    The variable x is 3, but the assertion expects x == 5, which is false.
  2. Step 2: Understand pytest behavior on failed assert

    pytest will fail the test and show the message "x is not equal to 5" to explain the failure.
  3. Final Answer:

    Test fails with message: x is not equal to 5 -> Option D
  4. Quick Check:

    False assert triggers failure message [OK]
Quick Trick: Failed assert shows message in pytest output [OK]
Common Mistakes:
MISTAKES
  • Assuming test passes despite false assert
  • Expecting syntax error from message
  • Thinking test skips automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes