added test for unique names when recievieng identical ids in parametrize
This commit is contained in:
parent
877ca5a0bf
commit
4b0237c8ee
|
@ -265,6 +265,13 @@ class TestMetafunc:
|
||||||
ids=["a", None])
|
ids=["a", None])
|
||||||
assert result == ["a", "3-4"]
|
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 test_addcall_and_parametrize(self):
|
||||||
def func(x, y): pass
|
def func(x, y): pass
|
||||||
metafunc = self.Metafunc(func)
|
metafunc = self.Metafunc(func)
|
||||||
|
@ -800,7 +807,7 @@ class TestMetafuncFunctional:
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
import pytest
|
import pytest
|
||||||
def pytest_generate_tests(metafunc):
|
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"])
|
ids=["basic", None, "advanced"])
|
||||||
|
|
||||||
def test_function(a, b):
|
def test_function(a, b):
|
||||||
|
@ -814,6 +821,23 @@ class TestMetafuncFunctional:
|
||||||
"*test_function*advanced*FAILED",
|
"*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"),
|
@pytest.mark.parametrize(("scope", "length"),
|
||||||
[("module", 2), ("function", 4)])
|
[("module", 2), ("function", 4)])
|
||||||
def test_parametrize_scope_overrides(self, testdir, scope, length):
|
def test_parametrize_scope_overrides(self, testdir, scope, length):
|
||||||
|
|
Loading…
Reference in New Issue