Bird
0
0

What will be the output when running this unittest code?

medium📝 Predict Output Q5 of 15
PyTest - Basics and Setup
What will be the output when running this unittest code?
import unittest

class TestMath(unittest.TestCase):
    def test_subtract(self):
        self.assertEqual(5 - 3, 2)

if __name__ == '__main__':
    unittest.main()
ASyntax error due to missing import
BTest passes with OK status
CTest fails with AssertionError
DTest is skipped because no test functions
Step-by-Step Solution
Solution:
  1. Step 1: Check the assertion in the unittest method

    assertEqual(5 - 3, 2) is true because 5 - 3 equals 2.
  2. Step 2: Understand unittest output on passing tests

    unittest shows OK when all tests pass without errors.
  3. Final Answer:

    Test passes with OK status -> Option B
  4. Quick Check:

    Correct assert = test passes [OK]
Quick Trick: unittest shows OK when asserts pass [OK]
Common Mistakes:
MISTAKES
  • Assuming test fails
  • Expecting syntax error
  • Thinking test skips without reason

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes