Skip to content

Commit

Permalink
remove complexity from match_keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Feb 22, 2018
1 parent cef0423 commit be2e3a9
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions _pytest/mark/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ class KeywordMapping(object):
def __init__(self, names):
self._names = names

@classmethod
def from_item(cls, item):
mapped_names = set()

# Add the names of the current item and any parent items
import pytest
for item in item.listchain():
if not isinstance(item, pytest.Instance):
mapped_names.add(item.name)

# Add the names added as extra keywords to current or parent items
for name in item.listextrakeywords():
mapped_names.add(name)

# Add the names attached to the current function through direct assignment
if hasattr(item, 'function'):
for name in item.function.__dict__:
mapped_names.add(name)

return cls(mapped_names)

def __getitem__(self, subname):
for name in self._names:
if subname in name:
Expand All @@ -61,24 +82,7 @@ def matchkeyword(colitem, keywordexpr):
Additionally, matches on names in the 'extra_keyword_matches' set of
any item, as well as names directly assigned to test functions.
"""
mapped_names = set()

# Add the names of the current item and any parent items
import pytest
for item in colitem.listchain():
if not isinstance(item, pytest.Instance):
mapped_names.add(item.name)

# Add the names added as extra keywords to current or parent items
for name in colitem.listextrakeywords():
mapped_names.add(name)

# Add the names attached to the current function through direct assignment
if hasattr(colitem, 'function'):
for name in colitem.function.__dict__:
mapped_names.add(name)

mapping = KeywordMapping(mapped_names)
mapping = KeywordMapping.from_item(colitem)
if " " not in keywordexpr:
# special case to allow for simple "-k pass" and "-k 1.3"
return mapping[keywordexpr]
Expand Down

0 comments on commit be2e3a9

Please sign in to comment.