💾 Archived View for tris.fyi › pydoc › unittest.loader captured on 2023-04-26 at 13:36:47. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
Loading unittests.
This class is responsible for loading tests according to various criteria and returning them wrapped in a TestSuite
A test suite is a composite test consisting of a number of TestCases. For use, create an instance of TestSuite, then add test case instances. When all tests have been added, the suite can be passed to a test runner, such as TextTestRunner. It will run the individual test cases in the order in which they were added, aggregating the results. When subclassing, do not forget to call the base class constructor.
addTest(self, test)
addTests(self, tests)
countTestCases(self)
debug(self) Run the tests without collecting errors in a TestResult
run(self, result, debug=False)
discover(self, start_dir, pattern='test*.py', top_level_dir=None) Find and return all test modules from the specified start directory, recursing into subdirectories to find them and return all tests found within them. Only test files that match the pattern will be loaded. (Using shell style pattern matching.) All test modules must be importable from the top level of the project. If the start directory is not the top level directory then the top level directory must be specified separately. If a test package name (directory with '__init__.py') matches the pattern then the package will be checked for a 'load_tests' function. If this exists then it will be called with (loader, tests, pattern) unless the package has already had load_tests called from the same discovery invocation, in which case the package module object is not scanned for tests - this ensures that when a package uses discover to further discover child tests that infinite recursion does not happen. If load_tests exists then discovery does *not* recurse into the package, load_tests is responsible for loading all tests in the package. The pattern is deliberately not stored as a loader attribute so that packages can continue discovery themselves. top_level_dir is stored so load_tests does not need to pass this argument in to loader.discover(). Paths are sorted before being imported to ensure reproducible execution order even on filesystems with non-alphabetical ordering like ext3/4.
getTestCaseNames(self, testCaseClass) Return a sorted sequence of method names found within testCaseClass
loadTestsFromModule(self, module, *args, pattern=None, **kws) Return a suite of all test cases contained in the given module
loadTestsFromName(self, name, module=None) Return a suite of all test cases given a string specifier. The name may resolve either to a module, a test case class, a test method within a test case class, or a callable object which returns a TestCase or TestSuite instance. The method optionally resolves the names relative to a given module.
loadTestsFromNames(self, names, module=None) Return a suite of all test cases found using the given sequence of string specifiers. See 'loadTestsFromName()'.
loadTestsFromTestCase(self, testCaseClass) Return a suite of all test cases contained in testCaseClass
three_way_cmp(x, y) Return -1 if x < y, 0 if x == y and 1 if x > y
testMethodPrefix = 'test'
testNamePatterns = None
findTestCases(module, prefix='test', sortUsing=<function three_way_cmp at 0x7f75e1079f30>, suiteClass=<class 'unittest.suite.TestSuite'>)
fnmatch(name, pat) Test whether FILENAME matches PATTERN. Patterns are Unix shell style: * matches everything ? matches any single character [seq] matches any character in seq [!seq] matches any char not in seq An initial period in FILENAME is not special. Both FILENAME and PATTERN are first case-normalized if the operating system requires it. If you don't want this, use fnmatchcase(FILENAME, PATTERN).
fnmatchcase(name, pat) Test whether FILENAME matches PATTERN, including case. This is a version of fnmatch() which doesn't case-normalize its arguments.
getTestCaseNames(testCaseClass, prefix, sortUsing=<function three_way_cmp at 0x7f75e1079f30>, testNamePatterns=None)
makeSuite(testCaseClass, prefix='test', sortUsing=<function three_way_cmp at 0x7f75e1079f30>, suiteClass=<class 'unittest.suite.TestSuite'>)
VALID_MODULE_NAME = re.compile('[_a-z]\\w*\\.py