Skip to content
Permalink
Browse files

Extracting common test setup into a fixture

  • Loading branch information
darrenburns committed Jan 29, 2020
1 parent a30afe7 commit 097348834b444cb55c7505aa41aa68e4ed09996c
Showing with 25 additions and 17 deletions.
  1. +25 −17 tests/test_testing.py
@@ -193,12 +193,16 @@ def _():
assert t.serr.getvalue() == ""


@test("@test attaches correct WardMeta to test function it wraps")
def _():
def in_func():
@fixture
def example_test():
def func():
assert 1 < 2
return func

@test("@test attaches correct WardMeta to test function it wraps")
def _(func=example_test):

out_func = testable_test(in_func)
out_func = testable_test(func)

assert out_func.ward_meta == WardMeta(
marker=None,
@@ -211,22 +215,26 @@ def in_func():


@test("@test doesn't attach WardMeta to functions in non-test modules")
def _():
def in_func():
assert 1 < 2

in_func.__module__ = "blah"

out_func = test('test')(in_func)
def _(func=example_test):
func.__module__ = "blah"
out_func = test("test")(func)

assert not hasattr(out_func, "ward_meta")


@test("@test attaches WardMeta to functions in modules ending in '_test'")
def _():
def in_func():
assert 1 < 2
def _(func=example_test):
func.__module__ = "its_a_test"
out_func = test("test")(func)

in_func.__module__ = "its_a_test"
out_func = test('test')(in_func)
assert hasattr(out_func, "ward_meta")

assert hasattr(out_func, "ward_meta")

@test("@test doesn't attach WardMeta to tests from imported modules")
def _(func=example_test):
# There is an underlying assumption here that a test from an
# imported module will always have a __module__ containing a "."
func.__module__ = "test_contains.dot_test"
out_func = test("test")(func)

assert not hasattr(out_func, "ward_meta")

0 comments on commit 0973488

Please sign in to comment.
You can’t perform that action at this time.