Skip to content

Commit e8d8c77

Browse files
committed
Pattern matching for xfail/skip files.
1 parent d295a0a commit e8d8c77

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

conftest.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ 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+
return False
135+
136+
121137
def pytest_collection_modifyitems(config, items):
122138
# 1. Prepare for iterating over items
123139
# -----------------------------------
@@ -165,13 +181,13 @@ def pytest_collection_modifyitems(config, items):
165181
markers = list(item.iter_markers())
166182
# skip if specified in skips file
167183
for id_ in skip_ids:
168-
if id_ in item.nodeid:
184+
if check_id_match(item.nodeid, id_):
169185
item.add_marker(mark.skip(reason=f"--skips-file ({skips_file})"))
170186
skip_id_matched[id_] = True
171187
break
172188
# xfail if specified in xfails file
173189
for id_ in xfail_ids:
174-
if id_ in item.nodeid:
190+
if check_id_match(item.nodeid, id_):
175191
item.add_marker(mark.xfail(reason=f"--xfails-file ({xfails_file})"))
176192
xfail_id_matched[id_] = True
177193
break

0 commit comments

Comments
 (0)