Skip to content

Commit c6cb4fd

Browse files
committed
Add support for an xfails file, and allow the files to be specified with a flag
1 parent 7e48141 commit c6cb4fd

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

conftest.py

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,17 @@ def pytest_addoption(parser):
4747
parser.addoption(
4848
"--ci",
4949
action="store_true",
50-
help="run just the tests appropiate for CI",
50+
help="run just the tests appropriate for CI",
51+
)
52+
parser.addoption(
53+
"--skips-file",
54+
action="store",
55+
help="file with tests to skip. Defaults to skips.txt"
56+
)
57+
parser.addoption(
58+
"--xfails-file",
59+
action="store",
60+
help="file with tests to skip. Defaults to xfails.txt"
5161
)
5262

5363

@@ -82,26 +92,49 @@ def xp_has_ext(ext: str) -> bool:
8292
return False
8393

8494

85-
skip_ids = []
86-
skips_path = Path(__file__).parent / "skips.txt"
87-
if skips_path.exists():
88-
with open(skips_path) as f:
89-
for line in f:
90-
if line.startswith("array_api_tests"):
91-
id_ = line.strip("\n")
92-
skip_ids.append(id_)
95+
def pytest_collection_modifyitems(config, items):
96+
skips_file = skips_path = config.getoption('--skips-file')
97+
if skips_file is None:
98+
skips_file = Path(__file__).parent / "skips.txt"
99+
if skips_file.exists():
100+
skips_path = skips_file
93101

102+
skip_ids = []
103+
if skips_path:
104+
with open(skips_path) as f:
105+
for line in f:
106+
if line.startswith("array_api_tests"):
107+
id_ = line.strip("\n")
108+
skip_ids.append(id_)
109+
110+
xfails_file = xfails_path = config.getoption('--xfails-file')
111+
if xfails_file is None:
112+
xfails_file = Path(__file__).parent / "xfails.txt"
113+
if xfails_file.exists():
114+
xfails_path = xfails_file
115+
116+
xfail_ids = []
117+
if xfails_path:
118+
with open(xfails_path) as f:
119+
for line in f:
120+
if line.startswith("array_api_tests"):
121+
id_ = line.strip("\n")
122+
xfail_ids.append(id_)
94123

95-
def pytest_collection_modifyitems(config, items):
96124
disabled_exts = config.getoption("--disable-extension")
97125
disabled_dds = config.getoption("--disable-data-dependent-shapes")
98126
ci = config.getoption("--ci")
99127
for item in items:
100128
markers = list(item.iter_markers())
101-
# skip if specified in skips.txt
129+
# skip if specified in skips file
102130
for id_ in skip_ids:
103131
if item.nodeid.startswith(id_):
104-
item.add_marker(mark.skip(reason="skips.txt"))
132+
item.add_marker(mark.skip(reason="skips file"))
133+
break
134+
# xfail if specified in xfails file
135+
for id_ in xfail_ids:
136+
if item.nodeid.startswith(id_):
137+
item.add_marker(mark.xfails(reason="xfails file"))
105138
break
106139
# skip if disabled or non-existent extension
107140
ext_mark = next((m for m in markers if m.name == "xp_extension"), None)

0 commit comments

Comments
 (0)