MCPcopy
hub / github.com/pytest-dev/pytest / from_item

Method from_item

src/_pytest/mark/__init__.py:170–198  ·  view source on GitHub ↗
(cls, item: Item)

Source from the content-addressed store, hash-verified

168
169 @classmethod
170 def from_item(cls, item: Item) -> KeywordMatcher:
171 mapped_names = set()
172
173 # Add the names of the current item and any parent items,
174 # except the Session and root Directory's which are not
175 # interesting for matching.
176 import pytest
177
178 for node in item.listchain():
179 if isinstance(node, pytest.Session):
180 continue
181 if isinstance(node, pytest.Directory) and isinstance(
182 node.parent, pytest.Session
183 ):
184 continue
185 mapped_names.add(node.name)
186
187 # Add the names added as extra keywords to current or parent items.
188 mapped_names.update(item.listextrakeywords())
189
190 # Add the names attached to the current function through direct assignment.
191 function_obj = getattr(item, "function", None)
192 if function_obj:
193 mapped_names.update(function_obj.__dict__)
194
195 # Add the markers to the keywords as we no longer handle them correctly.
196 mapped_names.update(mark.name for mark in item.iter_markers())
197
198 return cls(mapped_names)
199
200 def __call__(self, subname: str, /, **kwargs: str | int | bool | None) -> bool:
201 if kwargs:

Callers 1

deselect_by_keywordFunction · 0.80

Calls 5

clsFunction · 0.85
listchainMethod · 0.80
updateMethod · 0.80
listextrakeywordsMethod · 0.80
iter_markersMethod · 0.80

Tested by

no test coverage detected