Skip to content

Commit dbdca7b

Browse files
authored
Merge pull request #273 from hameerabbasi/skip-xfail-file-pattern
Pattern matching for xfail/skip files.
2 parents d295a0a + c7f5e03 commit dbdca7b

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

conftest.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,25 @@ def xp_has_ext(ext: str) -> bool:
118118
return False
119119

120120

121+
def check_id_match(id_, pattern):
122+
if id_ == pattern:
123+
return True
124+
125+
if id_.startswith(pattern.removesuffix("/") + "/"):
126+
return True
127+
128+
if pattern.endswith(".py") and id_.startswith(pattern):
129+
return True
130+
131+
if id_.split("::", maxsplit=2)[0] == pattern:
132+
return True
133+
134+
if id_.split("[", maxsplit=2)[0] == pattern:
135+
return True
136+
137+
return False
138+
139+
121140
def pytest_collection_modifyitems(config, items):
122141
# 1. Prepare for iterating over items
123142
# -----------------------------------
@@ -165,13 +184,13 @@ def pytest_collection_modifyitems(config, items):
165184
markers = list(item.iter_markers())
166185
# skip if specified in skips file
167186
for id_ in skip_ids:
168-
if id_ in item.nodeid:
187+
if check_id_match(item.nodeid, id_):
169188
item.add_marker(mark.skip(reason=f"--skips-file ({skips_file})"))
170189
skip_id_matched[id_] = True
171190
break
172191
# xfail if specified in xfails file
173192
for id_ in xfail_ids:
174-
if id_ in item.nodeid:
193+
if check_id_match(item.nodeid, id_):
175194
item.add_marker(mark.xfail(reason=f"--xfails-file ({xfails_file})"))
176195
xfail_id_matched[id_] = True
177196
break

0 commit comments

Comments
 (0)