diff --git a/_pytest/python.py b/_pytest/python.py index 913a3079e..26511ea05 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1529,7 +1529,8 @@ class FixtureManager: self._nodename2fixtureinfo = {} def getfixtureinfo(self, node, func, cls, funcargs=True): - key = (node, func.__name__) + # node is the "collection node" for "func" + key = (node, func) try: return self._nodename2fixtureinfo[key] except KeyError: diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index dc37a03a6..e830389e1 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -630,6 +630,22 @@ class TestMetafuncFunctional: "*3 passed*" ]) + def test_generate_same_function_names_issue403(self, testdir): + sub1 = testdir.makepyfile(""" + import pytest + + def make_tests(): + @pytest.mark.parametrize("x", range(2)) + def test_foo(x): + pass + return test_foo + + test_x = make_tests() + test_y = make_tests() + """) + reprec = testdir.inline_run() + reprec.assertoutcome(passed=4) + class TestMarkersWithParametrization: pytestmark = pytest.mark.issue308