Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _(example=example_test):
test_results = [
TestResult(test=example, outcome=TestOutcome.PASS),
TestResult(test=example, outcome=TestOutcome.SKIP),
TestResult(test=example, outcome=TestOutcome.XFAIL),
]
exit_code = get_exit_code(test_results)
expect(exit_code).equals(ExitCode.SUCCESS)
def _(example=example_test):
test_results = [
TestResult(test=example, outcome=TestOutcome.XPASS),
TestResult(test=example, outcome=TestOutcome.PASS),
]
exit_code = get_exit_code(test_results)
expect(exit_code).equals(ExitCode.FAILED)
def get_exit_code(results: Iterable[TestResult]) -> ExitCode:
if not results:
return ExitCode.NO_TESTS_FOUND
if any(
r.outcome == TestOutcome.FAIL or r.outcome == TestOutcome.XPASS for r in results
):
exit_code = ExitCode.FAILED
else:
exit_code = ExitCode.SUCCESS
return exit_code
def get_exit_code(results: Iterable[TestResult]) -> ExitCode:
if not results:
return ExitCode.NO_TESTS_FOUND
if any(
r.outcome == TestOutcome.FAIL or r.outcome == TestOutcome.XPASS for r in results
):
exit_code = ExitCode.FAILED
else:
exit_code = ExitCode.SUCCESS
return exit_code
def output_test_result_summary(
self, test_results: List[TestResult], time_taken: float
):
outcome_counts = self._get_outcome_counts(test_results)
if test_results:
chart = self.generate_chart(
num_passed=outcome_counts[TestOutcome.PASS],
num_failed=outcome_counts[TestOutcome.FAIL],
num_skipped=outcome_counts[TestOutcome.SKIP],
num_xfail=outcome_counts[TestOutcome.XFAIL],
num_unexp=outcome_counts[TestOutcome.XPASS],
)
print(chart, "")
exit_code = get_exit_code(test_results)
if exit_code == ExitCode.SUCCESS:
result = colored(exit_code.name, color="green")
else:
result = colored(exit_code.name, color="red")
output = f"{result} in {time_taken:.2f} seconds"
if test_results:
output += " [ "
if outcome_counts[TestOutcome.FAIL]:
output += f"{colored(str(outcome_counts[TestOutcome.FAIL]) + ' failed', color='red')} "
if outcome_counts[TestOutcome.XPASS]:
output += f"{colored(str(outcome_counts[TestOutcome.XPASS]) + ' xpassed', color='yellow')} "
if outcome_counts[TestOutcome.XFAIL]:
output += f"{colored(str(outcome_counts[TestOutcome.XFAIL]) + ' xfailed', color='magenta')} "
if outcome_counts[TestOutcome.SKIP]:
output += f"{colored(str(outcome_counts[TestOutcome.SKIP]) + ' skipped', color='blue')} "
def get_exit_code(results: Iterable[TestResult]) -> ExitCode:
if not results:
return ExitCode.NO_TESTS_FOUND
if any(
r.outcome == TestOutcome.FAIL or r.outcome == TestOutcome.XPASS for r in results
):
exit_code = ExitCode.FAILED
else:
exit_code = ExitCode.SUCCESS
return exit_code