implement full @pytest.setup function unittest.TestCase interaction

This commit is contained in:
holger krekel
2012-09-18 10:54:12 +02:00
parent d9c24552fc
commit a7c6688bd6
7 changed files with 129 additions and 16 deletions

View File

@@ -1792,8 +1792,7 @@ class TestFuncargManager:
reprec.assertoutcome(passed=1)
class TestSetupDiscovery:
def pytest_funcarg__testdir(self, request):
testdir = request.getfuncargvalue("testdir")
def pytest_funcarg__testdir(self, testdir):
testdir.makeconftest("""
import pytest
@pytest.setup()
@@ -1832,6 +1831,21 @@ class TestSetupDiscovery:
reprec = testdir.inline_run("-s")
reprec.assertoutcome(passed=1)
def test_setup_at_classlevel(self, testdir):
testdir.makepyfile("""
import pytest
class TestClass:
@pytest.setup()
def permethod(self, request):
request.instance.funcname = request.function.__name__
def test_method1(self):
assert self.funcname == "test_method1"
def test_method2(self):
assert self.funcname == "test_method2"
""")
reprec = testdir.inline_run("-s")
reprec.assertoutcome(passed=2)
def test_callables_nocode(self, testdir):
"""
a imported mock.call would break setup/factory discovery