Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xfail pytest tests from the command line

Tags:

python

pytest

I have a test suite where I need to mark some tests as xfail, but I cannot edit the test functions themselves to add markers. Is it possible to specify that some tests should be xfail from the command line using pytest? Or barring that, at least by adding something to pytest.ini or conftest.py?

like image 703
asmeurer Avatar asked Sep 08 '25 04:09

asmeurer


1 Answers

I don't know of a command line option to do this, but if you can filter out the respective tests, you may implement pytest_collection_modifyitemsand add an xfail marker to these tests:

conftest.py


names_to_be_xfailed = ("test_1", "test_3")

def pytest_collection_modifyitems(config, items):
    for item in items:
        if item.name in names_to_be_xfailed:
            item.add_marker("xfail")

or, if the name is not unique, you could also filter by item.nodeid.

like image 97
MrBean Bremen Avatar answered Sep 09 '25 17:09

MrBean Bremen