added test for unique names when recievieng identical ids in parametrize

This commit is contained in:
palaviv 2016-03-19 21:42:47 +02:00
parent 877ca5a0bf
commit 4b0237c8ee
1 changed files with 25 additions and 1 deletions

View File

@ -265,6 +265,13 @@ class TestMetafunc:
ids=["a", None])
assert result == ["a", "3-4"]
def test_idmaker_with_ids_unique_names(self):
from _pytest.python import idmaker
result = idmaker(("a", "b"), [(1, 2),
(3, 4)],
ids=["a", "a"])
assert result == ["0a", "1a"]
def test_addcall_and_parametrize(self):
def func(x, y): pass
metafunc = self.Metafunc(func)
@ -800,7 +807,7 @@ class TestMetafuncFunctional:
testdir.makepyfile("""
import pytest
def pytest_generate_tests(metafunc):
metafunc.parametrize(("a", "b"), [(1,1), (1,1) , (1,2)],
metafunc.parametrize(("a", "b"), [(1,1), (1,1), (1,2)],
ids=["basic", None, "advanced"])
def test_function(a, b):
@ -814,6 +821,23 @@ class TestMetafuncFunctional:
"*test_function*advanced*FAILED",
])
def test_parametrize_with_identical_ids_get_unique_names(self, testdir):
testdir.makepyfile("""
import pytest
def pytest_generate_tests(metafunc):
metafunc.parametrize(("a", "b"), [(1,1), (1,2)],
ids=["a", "a"])
def test_function(a, b):
assert a == b
""")
result = testdir.runpytest("-v")
assert result.ret == 1
result.stdout.fnmatch_lines_random([
"*test_function*0a*PASSED",
"*test_function*1a*FAILED"
])
@pytest.mark.parametrize(("scope", "length"),
[("module", 2), ("function", 4)])
def test_parametrize_scope_overrides(self, testdir, scope, length):