diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 0b719d183..f0f3dbd4c 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -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):