Add originalname attribute to Function

Related to #1790
This commit is contained in:
Bruno Oliveira 2016-08-03 22:56:12 -03:00
parent 530b0050b4
commit 1a79137d04
2 changed files with 20 additions and 3 deletions

View File

@ -361,7 +361,9 @@ class PyCollector(PyobjMixin, pytest.Collector):
yield Function(name=subname, parent=self,
callspec=callspec, callobj=funcobj,
fixtureinfo=fixtureinfo,
keywords={callspec.id:True})
keywords={callspec.id:True},
originalname=name,
)
def _marked(func, mark):
@ -1471,7 +1473,7 @@ class Function(FunctionMixin, pytest.Item, fixtures.FuncargnamesCompatAttr):
_genid = None
def __init__(self, name, parent, args=None, config=None,
callspec=None, callobj=NOTSET, keywords=None, session=None,
fixtureinfo=None):
fixtureinfo=None, originalname=None):
super(Function, self).__init__(name, parent, config=config,
session=session)
self._args = args
@ -1493,6 +1495,12 @@ class Function(FunctionMixin, pytest.Item, fixtures.FuncargnamesCompatAttr):
self.fixturenames = fixtureinfo.names_closure
self._initrequest()
#: original function name, without any decorations (for example
#: parametrization adds a ``"[...]"`` suffix to function names).
#:
#: .. versionadded:: 3.0
self.originalname = originalname
def _initrequest(self):
self.funcargs = {}
if self._isyieldedfunction():

View File

@ -634,6 +634,15 @@ class TestFunction:
result = testdir.runpytest()
result.stdout.fnmatch_lines('* 3 passed in *')
def test_function_original_name(self, testdir):
items = testdir.getitems("""
import pytest
@pytest.mark.parametrize('arg', [1,2])
def test_func(arg):
pass
""")
assert [x.originalname for x in items] == ['test_func', 'test_func']
class TestSorting:
def test_check_equality(self, testdir):