def run(self): if self.skip: return True print(yellow("<" * curses.tigetnum("cols")), flush=True) print(yellow("Starting {}...".format(self.description)), flush=True) self.print_full_test_cmd() test_retcode = subprocess.call(self.get_cmd(), shell=True) if test_retcode: self.status = TestStatus.FAILED print(red("{} failed, please check.".format(self.description)), flush=True) print(red(">" * curses.tigetnum("cols")), flush=True) else: self.status = TestStatus.PASSED print(green("{} successfully finished!".format(self.description)), flush=True) print(green(">" * curses.tigetnum("cols")), flush=True) return not test_retcode
def run_all_tests(tests_dir, jobs, test_tags, no_report, passed_list, test_list, distcc_hosts): hack_reference_exit = [] signal.signal(signal.SIGINT, lambda sig, frame: hack_reference_exit.append(1)) tests = collect_tests(tests_dir, test_tags, test_list) if not tests: print("Can't find any tests with [{}] {}".format( ", ".join(test_tags), "tag" if len(test_tags) == 1 else "tags")) sys.exit(1) results = [] with ThreadPool(jobs) as pool: tests_completed = 0 for test_result in pool.imap_unordered(partial(run_test, distcc_hosts), tests): if hack_reference_exit: print(yellow("Testing process was interrupted"), flush=True) break tests_completed = tests_completed + 1 test_result.print_short_report(len(tests), tests_completed) results.append(test_result) print("\nTesting results:", flush=True) skipped = len(tests) - len(results) failed = 0 passed = [] for test_result in results: if test_result.is_skipped(): skipped = skipped + 1 elif test_result.is_failed(): failed = failed + 1 else: passed.append( os.path.relpath(test_result.test_file_path, tests_dir)) if passed: print(" {}{}".format(green("passed: "), len(passed))) if passed_list: with open(passed_list, "w") as f: passed.sort() f.writelines("{}\n".format(l) for l in passed) if skipped: print(" {}{}".format(yellow("skipped: "), skipped)) if failed: print(" {}{}\n".format(red("failed: "), failed)) if not no_report: for test_result in results: test_result.print_fail_report() sys.exit(1 if failed else len(hack_reference_exit))
class TestStatus(Enum): FAILED = red("failed") PASSED = green("passed") SKIPPED = yellow("skipped")
def passed(test_file, artifacts): return TestResult(green("passed "), test_file, artifacts, None)