@@ -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,24 @@ def pytest_ignore_collect(path, config):
208210 return False
209211
210212
213+ def pytest_collection_modifyitems (items , config ):
214+ deselect_prefixes = tuple (config .getoption ("deselect" ) or [])
215+ if not deselect_prefixes :
216+ return
217+
218+ remaining = []
219+ deselected = []
220+ for colitem in items :
221+ if colitem .nodeid .startswith (deselect_prefixes ):
222+ deselected .append (colitem )
223+ else :
224+ remaining .append (colitem )
225+
226+ if deselected :
227+ config .hook .pytest_deselected (items = deselected )
228+ items [:] = remaining
229+
230+
211231@contextlib .contextmanager
212232def _patched_find_module ():
213233 """Patch bug in pkgutil.ImpImporter.find_module
0 commit comments