@@ -1395,11 +1395,41 @@ def __init__(
1395
1395
fixtureinfo : Optional [FuncFixtureInfo ] = None ,
1396
1396
originalname = None ,
1397
1397
) -> None :
1398
+ """
1399
+ param name: the full function name, including any decorations like those
1400
+ added by parametrization (``my_func[my_param]``).
1401
+ param parent: the parent Node.
1402
+ param args: (unused)
1403
+ param config: the pytest Config object
1404
+ param callspec: if given, this is function has been parametrized and the callspec contains
1405
+ meta information about the parametrization.
1406
+ param callobj: if given, the object which will be called when the Function is invoked,
1407
+ otherwise the callobj will be obtained from ``parent`` using ``originalname``
1408
+ param keywords: keywords bound to the function object for "-k" matching.
1409
+ param session: the pytest Session object
1410
+ param fixtureinfo: fixture information already resolved at this fixture node.
1411
+ param originalname:
1412
+ The attribute name to use for accessing the underlying function object.
1413
+ Defaults to ``name``. Set this if name is different from the original name,
1414
+ for example when it contains decorations like those added by parametrization
1415
+ (``my_func[my_param]``).
1416
+ """
1398
1417
super ().__init__ (name , parent , config = config , session = session )
1399
1418
self ._args = args
1400
1419
if callobj is not NOTSET :
1401
1420
self .obj = callobj
1402
1421
1422
+ #: Original function name, without any decorations (for example
1423
+ #: parametrization adds a ``"[...]"`` suffix to function names), used to access
1424
+ #: the underlying function object from ``parent`` (in case ``callobj`` is not given
1425
+ #: explicitly).
1426
+ #:
1427
+ #: .. versionadded:: 3.0
1428
+ self .originalname = originalname or name
1429
+
1430
+ # note: when FunctionDefinition is introduced, we should change ``originalname``
1431
+ # to a readonly property that returns FunctionDefinition.name
1432
+
1403
1433
self .keywords .update (self .obj .__dict__ )
1404
1434
self .own_markers .extend (get_unpacked_marks (self .obj ))
1405
1435
if callspec :
@@ -1434,12 +1464,6 @@ def __init__(
1434
1464
self .fixturenames = fixtureinfo .names_closure
1435
1465
self ._initrequest ()
1436
1466
1437
- #: original function name, without any decorations (for example
1438
- #: parametrization adds a ``"[...]"`` suffix to function names).
1439
- #:
1440
- #: .. versionadded:: 3.0
1441
- self .originalname = originalname
1442
-
1443
1467
@classmethod
1444
1468
def from_parent (cls , parent , ** kw ): # todo: determine sound type limitations
1445
1469
"""
@@ -1457,11 +1481,7 @@ def function(self):
1457
1481
return getimfunc (self .obj )
1458
1482
1459
1483
def _getobj (self ):
1460
- name = self .name
1461
- i = name .find ("[" ) # parametrization
1462
- if i != - 1 :
1463
- name = name [:i ]
1464
- return getattr (self .parent .obj , name )
1484
+ return getattr (self .parent .obj , self .originalname )
1465
1485
1466
1486
@property
1467
1487
def _pyfuncitem (self ):
0 commit comments