MCPcopy Index your code
hub / github.com/python/cpython / loadTestsFromModule

Method loadTestsFromModule

Lib/unittest/loader.py:97–119  ·  view source on GitHub ↗

Return a suite of all test cases contained in the given module

(self, module, *, pattern=None)

Source from the content-addressed store, hash-verified

95 return loaded_suite
96
97 def loadTestsFromModule(self, module, *, pattern=None):
98 """Return a suite of all test cases contained in the given module"""
99 tests = []
100 for name in dir(module):
101 obj = getattr(module, name)
102 if (
103 isinstance(obj, type)
104 and issubclass(obj, case.TestCase)
105 and obj not in (case.TestCase, case.FunctionTestCase)
106 ):
107 tests.append(self.loadTestsFromTestCase(obj))
108
109 load_tests = getattr(module, 'load_tests', None)
110 tests = self.suiteClass(tests)
111 if load_tests is not None:
112 try:
113 return load_tests(self, tests, pattern)
114 except Exception as e:
115 error_case, error_message = _make_failed_load_tests(
116 module.__name__, e, self.suiteClass)
117 self.errors.append(error_message)
118 return error_case
119 return tests
120
121 def loadTestsFromName(self, name, module=None):
122 """Return a suite of all test cases given a string specifier.

Callers 3

loadTestsFromNameMethod · 0.95
_find_test_pathMethod · 0.95
createTestsMethod · 0.45

Calls 4

loadTestsFromTestCaseMethod · 0.95
_make_failed_load_testsFunction · 0.85
load_testsFunction · 0.50
appendMethod · 0.45

Tested by

no test coverage detected