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))
def _print_artifacts(self): if self.artifacts: for file_type, artifact in self.artifacts: file_type_colored = red( file_type) if artifact.error_priority else yellow( file_type) print(" {} - {}".format(blue(artifact.file), file_type_colored), flush=True)
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 print_short_report(self, total_tests, test_number): width = 1 + int(math.log10(total_tests)) completed_str = "{0: >{width}}".format(test_number, width=width) additional_info = "" if self.failed_stage_msg: additional_info = self.failed_stage_msg elif self.artifacts: stderr_names = ", ".join(file_type for file_type, _ in self.artifacts) if stderr_names: additional_info = yellow("(got {})".format(stderr_names)) print("[{test_number}/{total_tests}] {status} {test_file} {additional_info}".format( test_number=completed_str, total_tests=total_tests, status=self.status, test_file=self.test_file_path, additional_info=additional_info), flush=True) self._print_artifacts()
class TestStatus(Enum): FAILED = red("failed") PASSED = green("passed") SKIPPED = yellow("skipped")
def skipped(test_file): return TestResult(yellow("skipped"), test_file, None, None)