简体   繁体   English

xfail pytest 从命令行测试

[英]xfail pytest tests from the command line

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.我有一个测试套件,我需要在其中将一些测试标记为 xfail,但我无法编辑测试函数本身来添加标记。 Is it possible to specify that some tests should be xfail from the command line using pytest?是否可以使用 pytest 从命令行指定某些测试应该是 xfail? Or barring that, at least by adding something to pytest.ini or conftest.py?或者除此之外,至少通过向 pytest.ini 或 conftest.py 添加一些内容?

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_modifyitems and add an xfail marker to these tests:我不知道执行此操作的命令行选项,但如果您可以过滤掉相应的测试,则可以实施pytest_collection_modifyitems并向这些测试添加xfail标记:

conftest.py比赛.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 .或者,如果名称不唯一,您也可以按item.nodeid进行过滤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM