Functional tests for id function

--HG--
branch : issue351
This commit is contained in:
Floris Bruynooghe 2014-10-08 00:11:32 +01:00
parent 4e35c00ab0
commit ab005a4261
1 changed files with 54 additions and 1 deletions

View File

@ -262,5 +262,58 @@ class TestNoselikeTestAttribute:
call = reprec.getcalls("pytest_collection_modifyitems")[0]
assert len(call.items) == 1
assert call.items[0].cls.__name__ == "TC"
@pytest.mark.issue351
class TestParameterize:
def test_idfn_marker(self, testdir):
testdir.makepyfile("""
import pytest
def idfn(param):
if param == 0:
return 'spam'
elif param == 1:
return 'ham'
else:
return None
@pytest.mark.parametrize('a,b', [(0, 2), (1, 2)], ids=idfn)
def test_params(a, b):
pass
""")
res = testdir.runpytest('--collect-only')
res.stdout.fnmatch_lines([
"*spam-2*",
"*ham-2*",
])
def test_idfn_fixture(self, testdir):
testdir.makepyfile("""
import pytest
def idfn(param):
if param == 0:
return 'spam'
elif param == 1:
return 'ham'
else:
return None
@pytest.fixture(params=[0, 1], ids=idfn)
def a(request):
return request.param
@pytest.fixture(params=[1, 2], ids=idfn)
def b(request):
return request.param
def test_params(a, b):
pass
""")
res = testdir.runpytest('--collect-only')
res.stdout.fnmatch_lines([
"*spam-2*",
"*ham-2*",
])