Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _():
def test():
pass
t = Test(fn=test, module_name=mod)
expect(t.is_parameterised).equals(False)
def named_test():
return Test(fn=named, module_name="my_module")
def example_test(module=module, fixtures=fixtures):
@fixture
def f():
return 123
def t(fix_a=f):
return fix_a
return Test(fn=t, module_name=module)
def my_test(
f1=exception_raising_fixture,
f2=global_fixture,
f3=module_fixture,
f4=default_fixture,
):
# Inject these fixtures into a test, and resolve them
# to ensure they're ready to be torn down.
@testable_test
def t(f1=f1, f2=f2, f3=f3, f4=f4):
pass
return Test(t, "")
def _():
def test():
pass
t = Test(fn=test, module_name=mod)
expect(t.get_parameterised_instances()).equals([t])
def dependent_test():
def x():
return 1
def _(a=x):
expect(1).equals(1)
return Test(fn=_, module_name=mod)
def anonymous_test():
def _():
expect(1).equals(1)
return Test(fn=_, module_name=mod)
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)
If the test is parameterised, return a list of `Test` objects representing
each test generated as a result of the parameterisation.
If the test is not parameterised, return a list containing only the test itself.
If the test is parameterised incorrectly, for example the number of
items don't match across occurrences of `each` in the test signature,
then a `ParameterisationError` is raised.
"""
if not self.is_parameterised:
return [self]
number_of_instances = self._find_number_of_instances()
generated_tests = []
for instance_index in range(number_of_instances):
generated_tests.append(
Test(
fn=self.fn,
module_name=self.module_name,
marker=self.marker,
description=self.description,
param_meta=ParamMeta(
instance_index=instance_index, group_size=number_of_instances
),
)
)
return generated_tests
meta: WardMeta = getattr(test_fn, "ward_meta")
yield Test(
fn=test_fn,
module_name=mod_name,
marker=meta.marker,
description=meta.description or "",
)
# Collect named tests from the module
for item in dir(mod):
if item.startswith("test_") and not item == "_":
test_name = item
test_fn = getattr(mod, test_name)
marker: Marker = getattr(test_fn, "ward_meta", WardMeta()).marker
if test_fn:
yield Test(fn=test_fn, module_name=mod_name, marker=marker)