def test(meth): @wraps(meth) def wrapper(self): global d with tempdir() as d.path: meth(self) return attest.test(wrapper)
def context(): """@Tests().context""" col = Tests(replace_tests=True) @col.test def test(calculated): assert calculated == 2 @col.context def context(): calculated = 1 + 1 yield calculated @col.test def noctx(): pass test() noctx() col2 = Tests() @col2.context def empty(): yield @col2.test def test2(): pass test2() col3 = Tests(replace_tests=True) @col3.context def multiple(): yield 1, 2, 3 @col3.test def test3(one, two, three): assert one == 1 assert two == 2 assert three == 3 @col3.test def test3_2(one, two): assert one == 1 assert two == 2 test3() test3_2() col4 = Tests(replace_tests=True) @col4.context def nested(): yield 1 @col4.context def nested(): yield @col4.context def nested(): yield 2 @col4.test def test4(one, two): assert one == 1 assert two == 2 test4() from contextlib import contextmanager @contextmanager def context5(): yield 1 col5 = Tests(contexts=[context5], replace_tests=True) @col5.test def test5(one): assert one == 1 test5()