Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _(skipped=skipped_test, example=example_test):
suite = Suite(tests=[example, skipped])
test_runs = list(suite.generate_test_runs())
expected_runs = [
TestResult(example, TestOutcome.PASS, None, ""),
TestResult(skipped, TestOutcome.SKIP, None, ""),
]
expect(test_runs).equals(expected_runs)
def _(suite=suite):
results = list(suite.generate_test_runs())
expected = [
TestResult(test=test, outcome=TestOutcome.PASS, error=None, message="")
for test in suite.tests
]
expect(results).equals(expected)
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 _(module=module):
def test_i_fail():
assert False
test = Test(fn=test_i_fail, module_name=module)
failing_suite = Suite(tests=[test])
results = failing_suite.generate_test_runs()
result = next(results)
expected_result = TestResult(
test=test, outcome=TestOutcome.FAIL, error=mock.ANY, message=""
)
expect(result).equals(expected_result)
expect(result.error).instance_of(AssertionError)
def _(skipped=skipped_test, example=example_test):
suite = Suite(tests=[example, skipped])
test_runs = list(suite.generate_test_runs())
expected_runs = [
TestResult(example, TestOutcome.PASS, None, ""),
TestResult(skipped, TestOutcome.SKIP, None, ""),
]
expect(test_runs).equals(expected_runs)
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 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