unittest.TestLoader.discover¶
-
TestLoader.discover(start_dir, pattern='test*.py', top_level_dir=None)[source]¶ Find and return all test modules from the specified start directory, recursing into subdirectories to find 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.
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().