simplify complexyity in mark plugin modifyitems
This commit is contained in:
parent
c8d24739ed
commit
935dd3aaa5
|
@ -5,6 +5,8 @@ from .structures import (
|
||||||
ParameterSet, EMPTY_PARAMETERSET_OPTION, MARK_GEN,
|
ParameterSet, EMPTY_PARAMETERSET_OPTION, MARK_GEN,
|
||||||
Mark, MarkInfo, MarkDecorator,
|
Mark, MarkInfo, MarkDecorator,
|
||||||
)
|
)
|
||||||
|
from .legacy import matchkeyword, matchmark
|
||||||
|
|
||||||
__all__ = ['Mark', 'MarkInfo', 'MarkDecorator']
|
__all__ = ['Mark', 'MarkInfo', 'MarkDecorator']
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,15 +73,8 @@ def pytest_cmdline_main(config):
|
||||||
pytest_cmdline_main.tryfirst = True
|
pytest_cmdline_main.tryfirst = True
|
||||||
|
|
||||||
|
|
||||||
def pytest_collection_modifyitems(items, config):
|
def deselect_by_keyword(items, config):
|
||||||
from .legacy import matchkeyword, matchmark
|
|
||||||
keywordexpr = config.option.keyword.lstrip()
|
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("-"):
|
if keywordexpr.startswith("-"):
|
||||||
keywordexpr = "not " + keywordexpr[1:]
|
keywordexpr = "not " + keywordexpr[1:]
|
||||||
selectuntil = False
|
selectuntil = False
|
||||||
|
@ -95,10 +90,6 @@ def pytest_collection_modifyitems(items, config):
|
||||||
else:
|
else:
|
||||||
if selectuntil:
|
if selectuntil:
|
||||||
keywordexpr = None
|
keywordexpr = None
|
||||||
if matchexpr:
|
|
||||||
if not matchmark(colitem, matchexpr):
|
|
||||||
deselected.append(colitem)
|
|
||||||
continue
|
|
||||||
remaining.append(colitem)
|
remaining.append(colitem)
|
||||||
|
|
||||||
if deselected:
|
if deselected:
|
||||||
|
@ -106,6 +97,29 @@ def pytest_collection_modifyitems(items, config):
|
||||||
items[:] = remaining
|
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):
|
def pytest_configure(config):
|
||||||
config._old_mark_config = MARK_GEN._config
|
config._old_mark_config = MARK_GEN._config
|
||||||
if config.option.strict:
|
if config.option.strict:
|
||||||
|
|
Loading…
Reference in New Issue