Closed ev-br closed 5 months ago
Here's how (TIL):
$ cat test_1.py
import pytest
def test_smth():
assert False
Then,
$ cat conftest.py
import pytest
def pytest_collection_modifyitems(config, items):
item = items[0]
item.add_marker(pytest.mark.xfail(reason='programmatic'))
produces
$ pytest test_1.py -v
================================= test session starts ==================================
platform linux -- Python 3.10.10, pytest-8.0.1, pluggy-1.3.0 -- /home/br/mambaforge/envs/scipy-dev/bin/python3.10
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/br/sweethome/proj/scipy/refguide_check_2/scrtch/.hypothesis/examples')
rootdir: /home/br/sweethome/proj/scipy/refguide_check_2/scrtch
plugins: scpdt-0.1, anyio-4.2.0, cov-4.0.0, timeout-2.1.0, hypothesis-6.84.3, xdist-3.2.1
collected 1 item
test_1.py::test_smth XFAIL (programmatic) [100%]
================================== 1 xfailed in 0.14s ==================================
-ignore
means skip collecting (tutorial/examples
)-skip
means applypytest.mark.skip
(or$ doctest +SKIP
) --- report as SKIPPED, do not run-xfail
means applypytest.mark.xfail
(or# may vary)
-- report as XFAIL/XPASS, run but do not checkNeed to allow both objects and paths, so that it works on both docstrings and tutorials.