extend Metafunc and write a pytest_generate_tests hook on the funcarg manager

which discovers factories
This commit is contained in:
holger krekel
2012-07-20 14:16:46 +02:00
parent e14459d45c
commit f358fe7154
3 changed files with 40 additions and 10 deletions

View File

@@ -989,6 +989,7 @@ class TestMetafunc:
def test_parametrize_functional(self, testdir):
testdir.makepyfile("""
def pytest_generate_tests(metafunc):
assert "test_parametrize_functional" in metafunc.parentid
metafunc.parametrize('x', [1,2], indirect=True)
metafunc.parametrize('y', [2])
def pytest_funcarg__x(request):
@@ -1680,3 +1681,20 @@ class TestFuncargManager:
""")
reprec = testdir.inline_run("-s")
reprec.assertoutcome(passed=1)
class TestFuncargMarker:
def test_parametrize(self, testdir):
testdir.makepyfile("""
import pytest
@pytest.mark.funcarg(params=["a", "b", "c"])
def pytest_funcarg__arg(request):
return request.param
l = []
def test_param(arg):
l.append(arg)
def test_result():
assert l == list("abc")
""")
reprec = testdir.inline_run()
reprec.assertoutcome(passed=4)