Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_result(self, outcome, exception=None):
with closing(self.sout), closing(self.serr):
if outcome in (TestOutcome.PASS, TestOutcome.SKIP):
result = TestResult(self, outcome)
else:
result = TestResult(
self,
outcome,
exception,
captured_stdout=self.sout.getvalue(),
captured_stderr=self.serr.getvalue(),
)
return result
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)
num_tests_per_module = self._test_counts_per_module()
for test in self.tests:
generated_tests = test.get_parameterised_instances()
for i, generated_test in enumerate(generated_tests):
num_tests_per_module[generated_test.path] -= 1
marker = generated_test.marker.name if generated_test.marker else None
if marker == "SKIP":
yield generated_test.get_result(TestOutcome.SKIP)
continue
try:
resolved_vals = generated_test.resolve_args(self.cache, iteration=i)
generated_test.format_description(resolved_vals)
generated_test(**resolved_vals)
outcome = (
TestOutcome.XPASS if marker == "XFAIL" else TestOutcome.PASS
)
yield generated_test.get_result(outcome)
except FixtureError as e:
yield generated_test.get_result(TestOutcome.FAIL, e)
continue
except Exception as e:
outcome = (
TestOutcome.XFAIL if marker == "XFAIL" else TestOutcome.FAIL
)
yield generated_test.get_result(outcome, e)
finally:
self.cache.teardown_fixtures_for_scope(
Scope.Test, scope_key=generated_test.id
)
if num_tests_per_module[generated_test.path] == 0:
self.cache.teardown_fixtures_for_scope(
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]
),