def main(): sys.path.insert(0, base) if 'MEMLEAK_EXE' in os.environ: return run_memleak_tests() parser = argparse.ArgumentParser(description='''\ Run the specified tests, or all tests if none are specified. Tests can be specified as either the test method name (without the leading test_) or a module name with a trailing period. ''') parser.add_argument( 'test_name', nargs='*', help= ('Test name (either a method name or a module name with a trailing period)' '. Note that if the name ends with a trailing underscore all tests methods' ' whose names start with the specified name are run.')) args = parser.parse_args() tests = find_tests() suites = [] for name in args.test_name: if name.endswith('.'): suites.append(filter_tests_by_module(tests, name[:-1])) else: suites.append(filter_tests_by_name(tests, name)) tests = unittest.TestSuite(suites) if suites else tests r = unittest.TextTestRunner result = r().run(tests) if not result.wasSuccessful(): raise SystemExit(1)
def run_memleak_tests(): tests = find_tests() tests = filter_tests_by_name(tests, 'asan_memleak') r = unittest.TextTestRunner result = r(verbosity=4).run(tests) if not result.wasSuccessful(): raise SystemExit(1)
def find_tests(): suites = [] for f in os.listdir(os.path.join(base, 'test')): n, ext = os.path.splitext(f) if ext == '.py' and n not in ('__init__', 'html5lib_adapter'): m = importlib.import_module('test.' + n) suite = unittest.defaultTestLoader.loadTestsFromModule(m) suites.append(suite) if 'SKIP_HTML5LIB' not in os.environ: from test.html5lib_adapter import find_tests suites.extend(find_tests()) return unittest.TestSuite(suites)