🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Testing Python Code: all 10 questions

Quiz: Testing Python Code · Question 5 of 10

What does this print? (code)

What does this print?

import io
import unittest

class T(unittest.TestCase):
    def test_a(self):
        self.assertEqual(2 + 2, 4)
    def test_b(self):
        self.assertEqual(len("abc"), 4)
    def helper(self):
        self.assertTrue(False)

r = unittest.TextTestRunner(stream=io.StringIO()).run(unittest.TestLoader().loadTestsFromTestCase(T))
print(r.testsRun, len(r.failures))
  1. A.3 2
  2. B.2 1
  3. C.2 0
  4. D.3 1
Answer & explanation

Correct answer: 2 1

helper does not start with test, so only two tests run, and test_b fails.

Can you get the rest right without peeking?

Take the timed Quiz: Testing Python Code quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →