Skip to content

Pattern matching for xfail/skip files. #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ def xp_has_ext(ext: str) -> bool:
return False


def check_id_match(id_, pattern):
if id_ == pattern:
return True

if id_.startswith(pattern.removesuffix("/") + "/"):
return True

if pattern.endswith(".py") and id_.startswith(pattern):
return True

if id_.split("::", maxsplit=2)[0] == pattern:
return True

if id_.split("[", maxsplit=2)[0] == pattern:
return True

return False


def pytest_collection_modifyitems(config, items):
# 1. Prepare for iterating over items
# -----------------------------------
Expand Down Expand Up @@ -165,13 +184,13 @@ def pytest_collection_modifyitems(config, items):
markers = list(item.iter_markers())
# skip if specified in skips file
for id_ in skip_ids:
if id_ in item.nodeid:
if check_id_match(item.nodeid, id_):
item.add_marker(mark.skip(reason=f"--skips-file ({skips_file})"))
skip_id_matched[id_] = True
break
# xfail if specified in xfails file
for id_ in xfail_ids:
if id_ in item.nodeid:
if check_id_match(item.nodeid, id_):
item.add_marker(mark.xfail(reason=f"--xfails-file ({xfails_file})"))
xfail_id_matched[id_] = True
break
Expand Down
Loading