Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def suite(example_test=example_test):
return Suite(tests=[example_test] * NUMBER_OF_TESTS)
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)
@fixture(scope=Scope.Module)
def a():
events.append("resolve")
yield "a"
events.append("teardown")
def test1(a=a):
events.append("test1")
def test2(a=a):
events.append("test2")
def test3(a=a):
events.append("test3")
suite = Suite(
tests=[
Test(fn=test1, module_name="module1"),
Test(fn=test2, module_name="module2"),
Test(fn=test3, module_name="module2"),
]
)
list(suite.generate_test_runs())
expect(events).equals(
[
"resolve", # Resolve at start of module1
"test1",
"teardown", # Teardown at end of module1
"resolve", # Resolve at start of module2
"test2",
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)
"-p", "--path", default=".", type=click.Path(exists=True), help="Path to tests."
)
@click.option(
"-f", "--filter", help="Only run tests whose names contain the filter argument as a substring."
)
@click.option(
"--fail-limit", type=int, help="The number of failures to cancel the run after."
)
def run(path, filter, fail_limit):
term = Terminal()
mod_infos = get_info_for_modules(path)
modules = list(load_modules(mod_infos))
tests = list(get_tests_in_modules(modules, filter=filter))
suite = Suite(tests=tests, fixture_registry=fixture_registry)
test_results = suite.generate_test_runs()
writer = SimpleTestResultWrite(terminal=term, suite=suite)
results = writer.output_all_test_results(
test_results,
fail_limit=fail_limit,
)
if any(r.outcome == TestOutcome.FAIL for r in results):
exit_code = ExitCode.TEST_FAILED
else:
exit_code = ExitCode.SUCCESS
sys.exit(exit_code.value)
def run(path, filter, fail_limit):
start_run = default_timer()
mod_infos = get_info_for_modules(path)
modules = list(load_modules(mod_infos))
tests = list(get_tests_in_modules(modules, filter=filter))
time_to_collect = default_timer() - start_run
suite = Suite(tests=tests, fixture_registry=fixture_registry)
test_results = suite.generate_test_runs()
writer = SimpleTestResultWrite(suite=suite)
coverage = Coverage()
coverage.start()
results = writer.output_all_test_results(test_results, time_to_collect=time_to_collect, fail_limit=fail_limit)
coverage.stop()
with closing(io.StringIO()) as coverage_out:
coverage.report(file=coverage_out)
coverage_report = coverage_out.getvalue()
time_taken = default_timer() - start_run
writer.output_test_result_summary(results, time_taken)
print(coverage_report)