Bird
0
0

What will be the output when running this pytest code?

medium📝 Predict Output Q4 of 15
PyTest - Test Organization
What will be the output when running this pytest code?
class TestExample:
    def test_one(self):
        assert 1 + 1 == 2
    def test_two(self):
        assert 2 * 2 == 5
ABoth tests pass
BOne test passes, one test fails
CBoth tests fail
DSyntax error, tests won't run
Step-by-Step Solution
Solution:
  1. Step 1: Analyze each test assertion

    test_one asserts 1+1==2 which is true; test_two asserts 2*2==5 which is false.
  2. Step 2: Determine test results

    test_one passes; test_two fails; pytest reports one pass and one fail.
  3. Final Answer:

    One test passes, one test fails -> Option B
  4. Quick Check:

    Assertions evaluated correctly = A [OK]
Quick Trick: Check each assertion result carefully to predict pass/fail [OK]
Common Mistakes:
MISTAKES
  • Assuming both tests pass without checking assertions
  • Thinking pytest stops after first failure
  • Confusing syntax errors with assertion failures

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes