def detect_flaky_tests(temp_dir, config_file): config = Config(config_file) number_of_invocations = int(config.numberOfInvocations) clone_dir_path = os.path.join(temp_dir, "cloned") test_report_backup = os.path.join(temp_dir, "backup") clone_success = _clone(config.repository, clone_dir_path) if clone_success: os.mkdir(test_report_backup) for i in range(number_of_invocations): _execute_test(config.command, cwd=clone_dir_path) toDirectory = os.path.join(test_report_backup, str(i)) os.mkdir(toDirectory) fromDirectory = os.path.join(clone_dir_path, config.testreport) copy_tree(fromDirectory, toDirectory) test_results = junit.extract_test_results(number_of_invocations, test_report_backup) tests_are_flaky = False for test in test_results: if len(test_results[test]) != number_of_invocations and len( test_results[test]) != 0: tests_are_flaky = True pretty_print.success("{} is flaky".format(test)) t = trello.Trello(config.trello) t.make_trello_task(test, test_results[test]) java.ignore_test(test, clone_dir_path) if tests_are_flaky: branch_name = _commit_and_push(clone_dir_path) github = Github(config.github) github.create_pull_request(repository=config.repository, title='Ignoring flaky tests', body='Mark `@Ignore` for flaky tests', branch_name=branch_name, base_branch='master')