Skip to content

Commit 6144df4

Browse files
committed
ENH: add ARRAY_API_TESTS_XFAIL_MARK to turn xfails into skips
1 parent 66e8cad commit 6144df4

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,18 @@ ARRAY_API_TESTS_SKIP_DTYPES=uint16,uint32,uint64 pytest array_api_tests/
305305
Note that skipping certain essential dtypes such as `bool` and the default
306306
floating-point dtype is not supported.
307307
308+
#### Turning xfails into skips
309+
310+
Keeping a large number of ``xfails`` can have drastic effects on the run time. This is due
311+
to the way `hypothesis` works: when it detects a failure, it does a large amount
312+
of work to simplify the failing example.
313+
If the run time of the test suite becomes a problem, you can use the
314+
``ARRAY_API_TESTS_XFAIL_MARK`` environment variable: setting it to ``skip`` skips the
315+
entries from the ``xfail.txt`` file instead of xfailing them. Anecdotally, we saw
316+
speed-ups by a factor of 4-5---which allowed us to use 4-5 larger values of
317+
``--max-examples`` within the same time budget.
318+
319+
308320
## Contributing
309321
310322
### Remain in-scope

conftest.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ def check_id_match(id_, pattern):
144144
return False
145145

146146

147+
def get_xfail_mark():
148+
"""Skip or xfail tests from the xfails-file.txt."""
149+
m = os.environ.get("ARRAY_API_TESTS_XFAIL_MARK", "xfail")
150+
if m == "xfail":
151+
return mark.xfail
152+
elif m == "skip":
153+
return mark.skip
154+
else:
155+
raise ValueError(
156+
f'ARRAY_API_TESTS_XFAIL_MARK value should be one of "skip" or "xfail" '
157+
f'got {m} instead.'
158+
)
159+
160+
147161
def pytest_collection_modifyitems(config, items):
148162
# 1. Prepare for iterating over items
149163
# -----------------------------------
@@ -187,6 +201,8 @@ def pytest_collection_modifyitems(config, items):
187201
# 2. Iterate through items and apply markers accordingly
188202
# ------------------------------------------------------
189203

204+
xfail_mark = get_xfail_mark()
205+
190206
for item in items:
191207
markers = list(item.iter_markers())
192208
# skip if specified in skips file
@@ -198,7 +214,7 @@ def pytest_collection_modifyitems(config, items):
198214
# xfail if specified in xfails file
199215
for id_ in xfail_ids:
200216
if check_id_match(item.nodeid, id_):
201-
item.add_marker(mark.xfail(reason=f"--xfails-file ({xfails_file})"))
217+
item.add_marker(xfail_mark(reason=f"--xfails-file ({xfails_file})"))
202218
xfail_id_matched[id_] = True
203219
break
204220
# skip if disabled or non-existent extension

0 commit comments

Comments
 (0)