Skip to content

Commit 456a253

Browse files
committed
python: optimize node keywords initialization
If we do the `update`s in the right order, we can avoid the `mark.name not in self.keywords` check, since `self.keywords` starts out clean and `update` will override previously set keywords.
1 parent 3c69bc9 commit 456a253

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/_pytest/python.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,25 +1658,20 @@ def __init__(
16581658
# Note: when FunctionDefinition is introduced, we should change ``originalname``
16591659
# to a readonly property that returns FunctionDefinition.name.
16601660

1661-
self.keywords.update(self.obj.__dict__)
16621661
self.own_markers.extend(get_unpacked_marks(self.obj))
16631662
if callspec:
16641663
self.callspec = callspec
16651664
self.own_markers.extend(callspec.marks)
1666-
if keywords:
1667-
self.keywords.update(keywords)
16681665

16691666
# todo: this is a hell of a hack
16701667
# https://github.com/pytest-dev/pytest/issues/4569
1671-
1668+
# Note: the order of the updates is important here; indicates what
1669+
# takes priority (ctor argument over function attributes over markers).
16721670
# Take own_markers only; NodeKeywords handles parent traversal on its own.
1673-
self.keywords.update(
1674-
{
1675-
mark.name: mark
1676-
for mark in self.own_markers
1677-
if mark.name not in self.keywords
1678-
}
1679-
)
1671+
self.keywords.update({mark.name: mark for mark in self.own_markers})
1672+
self.keywords.update(self.obj.__dict__)
1673+
if keywords:
1674+
self.keywords.update(keywords)
16801675

16811676
if fixtureinfo is None:
16821677
fixtureinfo = self.session._fixturemanager.getfixtureinfo(

0 commit comments

Comments
 (0)