Skip to content

Commit

Permalink
simplify complexyity in mark plugin modifyitems
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Feb 22, 2018
1 parent c8d2473 commit 935dd3a
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions _pytest/mark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
ParameterSet, EMPTY_PARAMETERSET_OPTION, MARK_GEN,
Mark, MarkInfo, MarkDecorator,
)
from .legacy import matchkeyword, matchmark

__all__ = ['Mark', 'MarkInfo', 'MarkDecorator']


Expand Down Expand Up @@ -71,15 +73,8 @@ def pytest_cmdline_main(config):
pytest_cmdline_main.tryfirst = True


def pytest_collection_modifyitems(items, config):
from .legacy import matchkeyword, matchmark
def deselect_by_keyword(items, config):
keywordexpr = config.option.keyword.lstrip()
matchexpr = config.option.markexpr
if not keywordexpr and not matchexpr:
return
# pytest used to allow "-" for negating
# but today we just allow "-" at the beginning, use "not" instead
# we probably remove "-" altogether soon
if keywordexpr.startswith("-"):
keywordexpr = "not " + keywordexpr[1:]
selectuntil = False
Expand All @@ -95,17 +90,36 @@ def pytest_collection_modifyitems(items, config):
else:
if selectuntil:
keywordexpr = None
if matchexpr:
if not matchmark(colitem, matchexpr):
deselected.append(colitem)
continue
remaining.append(colitem)

if deselected:
config.hook.pytest_deselected(items=deselected)
items[:] = remaining


def deselect_by_mark(items, config):
matchexpr = config.option.markexpr
if not matchexpr:
return

remaining = []
deselected = []
for item in items:
if matchmark(item, matchexpr):
remaining.append(item)
else:
deselected.append(item)

if deselected:
config.hook.pytest_deselected(items=deselected)
items[:] = remaining


def pytest_collection_modifyitems(items, config):
deselect_by_keyword(items, config)
deselect_by_mark(items, config)


def pytest_configure(config):
config._old_mark_config = MARK_GEN._config
if config.option.strict:
Expand Down

0 comments on commit 935dd3a

Please sign in to comment.