@@ -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 = "nodeid_prefix" ,
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,26 @@ 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+ break
225+ else :
226+ remaining .append (colitem )
227+
228+ if deselected :
229+ config .hook .pytest_deselected (items = deselected )
230+ items [:] = remaining
231+
232+
211233@contextlib .contextmanager
212234def _patched_find_module ():
213235 """Patch bug in pkgutil.ImpImporter.find_module
0 commit comments