@@ -185,13 +185,22 @@ By default, tests for the optional Array API extensions such as
185185will be skipped if not present in the specified array module. You can purposely
186186skip testing extension(s) via the ` --disable-extension ` option.
187187
188- #### Skip test cases
188+ #### Skip or XFAIL test cases
189189
190- Test cases you want to skip can be specified in a ` skips.txt ` file in the root
191- of this repository, e.g.:
190+ Test cases you want to skip can be specified in a skips or XFAILS file. The
191+ difference between skip and XFAIL is that XFAIL tests are still run and
192+ reported as XPASS if they pass.
193+
194+ By default, the skips and xfails files are ` skips.txt ` and ` fails.txt ` in the root
195+ of this repository, but any file can be specified with the ` --skips-file ` and
196+ ` --xfails-file ` command line flags.
197+
198+ The files should list the test ids to be skipped/xfailed. Empty lines and
199+ lines starting with ` # ` are ignored. The test id can be any substring of the
200+ test ids to skip/xfail.
192201
193202```
194- # ./ skips.txt
203+ # skips.txt or xfails .txt
195204# Line comments can be denoted with the hash symbol (#)
196205
197206# Skip specific test case, e.g. when argsort() does not respect relative order
@@ -207,39 +216,81 @@ array_api_tests/test_add[__iadd__(x, s)]
207216array_api_tests/test_set_functions.py
208217```
209218
210- For GitHub Actions, you might like to keep everything in the workflow config
211- instead of having a seperate ` skips.txt ` file, e.g.:
219+ Here is an example GitHub Actions workflow file, where the xfails are stored
220+ in ` array-api-tests.xfails.txt ` in the base of the ` your-array-library ` repo.
221+
222+ If you want, you can use ` -o xfail_strict=True ` , which causes XPASS tests (XFAIL
223+ tests that actually pass) to fail the test suite. However, be aware that
224+ XFAILures can be flaky (see below, so this may not be a good idea unless you
225+ use some other mitigation of such flakyness).
226+
227+ If you don't want this behavior, you can remove it, or use ` --skips-file `
228+ instead of ` --xfails-file ` .
212229
213230``` yaml
214231# ./.github/workflows/array_api.yml
215- ...
216- ...
217- - name : Run the test suite
232+ jobs :
233+ tests :
234+ runs-on : ubuntu-latest
235+ strategy :
236+ matrix :
237+ python-version : ['3.8', '3.9', '3.10', '3.11']
238+
239+ steps :
240+ - name : Checkout <your array library>
241+ uses : actions/checkout@v3
242+ with :
243+ path : your-array-library
244+
245+ - name : Checkout array-api-tests
246+ uses : actions/checkout@v3
247+ with :
248+ repository : data-apis/array-api-tests
249+ submodules : ' true'
250+ path : array-api-tests
251+
252+ - name : Run the array API test suite
218253 env :
219254 ARRAY_API_TESTS_MODULE : your.array.api.namespace
220255 run : |
221- # Skip test cases with known issues
222- cat << EOF >> skips.txt
223-
224- # Comments can still work here
225- array_api_tests/test_sorting_functions.py::test_argsort
226- array_api_tests/test_add[__iadd__(x1, x2)]
227- array_api_tests/test_add[__iadd__(x, s)]
228- array_api_tests/test_set_functions.py
229-
230- EOF
231-
232- pytest -v -rxXfE --ci
256+ export PYTHONPATH="${GITHUB_WORKSPACE}/your-array-library"
257+ cd ${GITHUB_WORKSPACE}/array-api-tests
258+ pytest -v -rxXfE --ci --xfails-file ${GITHUB_WORKSPACE}/your-array-library/array-api-tests-xfails.txt array_api_tests/
233259` ` `
234260
261+ > **Warning**
262+ >
263+ > XFAIL tests that use Hypothesis (basically every test in the test suite except
264+ > those in test_has_names.py) can be flaky, due to the fact that Hypothesis
265+ > might not always run the test with an input that causes the test to fail.
266+ > There are several ways to avoid this problem:
267+ >
268+ > - Increase the maximum number of examples, e.g., by adding ` --max-examples
269+ > 200` to the test command (the default is `100`, see below). This will
270+ > make it more likely that the failing case will be found, but it will also
271+ > make the tests take longer to run.
272+ > - Don't use `-o xfail_strict=True`. This will make it so that if an XFAIL
273+ > test passes, it will alert you in the test summary but will not cause the
274+ > test run to register as failed.
275+ > - Use skips instead of XFAILS. The difference between XFAIL and skip is that
276+ > a skipped test is never run at all, whereas an XFAIL test is always run
277+ > but ignored if it fails.
278+ > - Save the [Hypothesis examples
279+ > database](https://hypothesis.readthedocs.io/en/latest/database.html)
280+ > persistently on CI. That way as soon as a run finds one failing example,
281+ > it will always re-run future runs with that example. But note that the
282+ > Hypothesis examples database may be cleared when a new version of
283+ > Hypothesis or the test suite is released.
284+
235285# ### Max examples
236286
237287The tests make heavy use
238288[Hypothesis](https://hypothesis.readthedocs.io/en/latest/). You can configure
239- how many examples are generated using the ` --max-examples` flag, which defaults
240- to 100. Lower values can be useful for quick checks, and larger values should
241- result in more rigorous runs. For example, `--max-examples 10_000` may find bugs
242- where default runs don't but will take much longer to run.
289+ how many examples are generated using the `--max-examples` flag, which
290+ defaults to `100`. Lower values can be useful for quick checks, and larger
291+ values should result in more rigorous runs. For example, `--max-examples
292+ 10_000` may find bugs where default runs don't but will take much longer to
293+ run.
243294
244295
245296# # Contributing
0 commit comments