Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

unittest.TestResult.testsRun — number of tests run

The unittest.TestResult.testsRun attribute reports the total number of tests run so far, not the number of tests that passed.

Version: Python 3.14; repository image, production runtime not attested

Syntax

result.testsRun

unittest.TestResult.testsRun is an attribute of a result object that stores the total number of tests run so far. Read it as result.testsRun, without parentheses: it is not a method.

Do not interpret this value as the number of successes or the number of all planned tests. Failures and errors are recorded separately in failures and errors. In the example, suite.run(result) runs two tests, and the supplied TestResult increments testsRun by one as each test starts. Both tests pass, but the default addSuccess() method does not store a success record. print(result.testsRun) prints 2.

Examples

import unittest

class ArithmeticTests(unittest.TestCase):
    def test_sum(self):
        self.assertEqual(2 + 3, 5)

    def test_product(self):
        self.assertEqual(2 * 3, 6)

suite = unittest.TestSuite([
    ArithmeticTests("test_sum"),
    ArithmeticTests("test_product"),
])
result = unittest.TestResult()
suite.run(result)
print(result.testsRun)

Result

2

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources