Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

unittest.defaultTestLoader — shared test loader

unittest.defaultTestLoader is a ready-made TestLoader instance that builds test suites without creating a separate loader.

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

Syntax

unittest.defaultTestLoader.loadTestsFromTestCase(testCaseClass)

unittest.defaultTestLoader is a shared instance of unittest.TestLoader, not a class or function. Use it without () when you need no custom configuration. Loading builds a test suite; it does not execute the tests.

loadTestsFromTestCase() accepts a subclass of unittest.TestCase. By default, it selects methods whose names start with test. The example separately builds the suite and executes it through suite.run(result).

Configuration changes to this shared object affect subsequent users. Create unittest.TestLoader() for custom settings. Its errors list retains nonfatal loading errors and is not automatically reset.

Examples

import unittest


class AdditionTests(unittest.TestCase):
    def test_addition(self):
        self.assertEqual(2 + 3, 5)


suite = unittest.defaultTestLoader.loadTestsFromTestCase(AdditionTests)
print(suite.countTestCases())
result = unittest.TestResult()
suite.run(result)
print(result.testsRun, result.wasSuccessful())

Result

1
1 True

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