@@ -66,6 +66,8 @@ def pytest_addoption(parser):
6666 help = "try to interpret all arguments as python packages." )
6767 group .addoption ("--ignore" , action = "append" , metavar = "path" ,
6868 help = "ignore path during collection (multi-allowed)." )
69+ group .addoption ("--deselect" , action = "append" , metavar = "item" ,
70+ help = "deselect item during collection (multi-allowed)." )
6971 # when changing this to --conf-cut-dir, config.py Conftest.setinitial
7072 # needs upgrading as well
7173 group .addoption ('--confcutdir' , dest = "confcutdir" , default = None ,
@@ -208,6 +210,25 @@ def pytest_ignore_collect(path, config):
208210 return False
209211
210212
213+ def pytest_collection_modifyitems (items , config ):
214+ deselectopt = config .getoption ("deselect" )
215+ if deselectopt is None :
216+ return
217+
218+ remaining = []
219+ deselected = []
220+ for colitem in items :
221+ for opt in deselectopt :
222+ if colitem .nodeid .startswith (opt ):
223+ deselected .append (colitem )
224+ else :
225+ remaining .append (colitem )
226+
227+ if deselected :
228+ config .hook .pytest_deselected (items = deselected )
229+ items [:] = remaining
230+
231+
211232@contextlib .contextmanager
212233def _patched_find_module ():
213234 """Patch bug in pkgutil.ImpImporter.find_module
0 commit comments