From 92b2d4786d1ce8ffc4078ea76bd3015b6823799f Mon Sep 17 00:00:00 2001 From: hpk Date: Thu, 19 Mar 2009 15:34:33 +0100 Subject: [PATCH] [svn r63073] make sure that generated test names are always unique --HG-- branch : trunk --- py/test/pycollect.py | 4 ++++ py/test/testing/test_pycollect.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/py/test/pycollect.py b/py/test/pycollect.py index 25cebaeae..57a54a7e7 100644 --- a/py/test/pycollect.py +++ b/py/test/pycollect.py @@ -288,6 +288,7 @@ class Generator(FunctionMixin, PyCollectorMixin, py.test.collect.Collector): # otherwise we could avoid global setupstate self.config._setupstate.prepare(self) l = [] + seen = {} for i, x in py.builtin.enumerate(self.obj()): name, call, args = self.getcallargs(x) if not callable(call): @@ -296,6 +297,9 @@ class Generator(FunctionMixin, PyCollectorMixin, py.test.collect.Collector): name = "[%d]" % i else: name = "['%s']" % name + if name in seen: + raise ValueError("%r generated tests with non-unique name %r" %(self, name)) + seen[name] = True l.append(self.Function(name, self, args=args, callobj=call)) return l diff --git a/py/test/testing/test_pycollect.py b/py/test/testing/test_pycollect.py index b5d9033dd..64f4f8705 100644 --- a/py/test/testing/test_pycollect.py +++ b/py/test/testing/test_pycollect.py @@ -140,6 +140,20 @@ class TestGenerator: assert gencolitems[1].name == "['fortytwo']" assert gencolitems[1].obj.func_name == 'func1' + def test_generative_functions_unique_explicit_names(self, testdir): + # generative + modcol = testdir.getmodulecol(""" + def func(): pass + def test_gen(): + yield "name", func + yield "name", func + """) + colitems = modcol.collect() + assert len(colitems) == 1 + gencol = colitems[0] + assert isinstance(gencol, py.test.collect.Generator) + py.test.raises(ValueError, "gencol.collect()") + def test_generative_methods_with_explicit_names(self, testdir): modcol = testdir.getmodulecol(""" def func1(arg, arg2):