From b4797d62956a1e9ac04d30d88c940f52c9f5eb42 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 16 Dec 2013 07:47:59 +0100 Subject: [PATCH] fix issue403 : allow same-name parametrized functions within a collector --- _pytest/python.py | 3 ++- testing/python/metafunc.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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