def discover_tests(explicitly_enumerated_tests, exclude_enumerated_tests=False): if not explicitly_enumerated_tests: return autodiscover_tests() if exclude_enumerated_tests: return unittest.TestLoader().loadTestsFromNames([ test_name for test_name in tests_from_suite(autodiscover_tests()) if test_name not in explicitly_enumerated_tests ]) return unittest.TestLoader().loadTestsFromNames(explicitly_enumerated_tests)
def autodiscover_tests(): #...Find all the test modules by recursing into subdirectories from the #specified start directory... #...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... #So test are loaded from PACKAGE_DIR/pcs but their names starts with "pcs." return unittest.TestLoader().discover( start_dir=os.path.join(PACKAGE_DIR, "pcs"), pattern='test_*.py', top_level_dir=PACKAGE_DIR, )