Bird
0
0

What will be the result of this pytest assertion?

medium📝 Predict Output Q13 of 15
PyTest - Writing Assertions
What will be the result of this pytest assertion?
def test_numbers():
    x = 10
    y = 5 + 5
    assert x == y
ASyntax error in assertion
BTest fails because 10 does not equal 5
CTest passes because 10 equals 10
DTest fails because variables are different
Step-by-Step Solution
Solution:
  1. Step 1: Calculate values of variables

    Variable x is 10, and y is calculated as 5 + 5, which equals 10.
  2. Step 2: Evaluate assertion condition

    The assertion assert x == y checks if 10 equals 10, which is true, so the test passes.
  3. Final Answer:

    Test passes because 10 equals 10 -> Option C
  4. Quick Check:

    10 == 10 is True [OK]
Quick Trick: Add values before comparing for equality [OK]
Common Mistakes:
MISTAKES
  • Assuming variables differ without calculation
  • Confusing syntax errors with logic errors
  • Ignoring that 5 + 5 equals 10

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes