Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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')} "
if outcome_counts[TestOutcome.PASS]:
output += f"{colored(str(outcome_counts[TestOutcome.PASS]) + ' passed', color='green')}"
if test_results:
output += " ] "
print(output)
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
padded_outcome = f" {test_result.outcome.name[:4]} "
# If we're executing a parameterised test
param_meta = test_result.test.param_meta
if param_meta.group_size > 1:
iter_indicator = f" [{param_meta.instance_index + 1}/{param_meta.group_size}]"
else:
iter_indicator = ""
mod_name = lightblack(
f"{test_result.test.module_name}:"
f"{test_result.test.line_number}"
f"{iter_indicator}: "
)
if (
test_result.outcome == TestOutcome.SKIP
or test_result.outcome == TestOutcome.XFAIL
):
reason = test_result.test.marker.reason or ""
if reason:
reason = lightblack(f" [{reason}]")
else:
reason = ""
name_or_desc = test_result.test.description
print(
colored(padded_outcome, color="grey", on_color=bg),
mod_name + name_or_desc,
reason,
)
def _get_outcome_counts(
self, test_results: List[TestResult]
) -> Dict[TestOutcome, int]:
return {
TestOutcome.PASS: len(
[r for r in test_results if r.outcome == TestOutcome.PASS]
),
TestOutcome.FAIL: len(
[r for r in test_results if r.outcome == TestOutcome.FAIL]
),
TestOutcome.SKIP: len(
[r for r in test_results if r.outcome == TestOutcome.SKIP]
),
TestOutcome.XFAIL: len(
[r for r in test_results if r.outcome == TestOutcome.XFAIL]
),
TestOutcome.XPASS: len(
[r for r in test_results if r.outcome == 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')} "
if outcome_counts[TestOutcome.PASS]:
output += f"{colored(str(outcome_counts[TestOutcome.PASS]) + ' passed', color='green')}"
if test_results:
output += " ] "
print(output)