【问题标题】:How to report reasons for skipped tests when running pytest with --collect-only?使用 --collect-only 运行 pytest 时如何报告跳过测试的原因?
【发布时间】:2022-01-11 18:24:50
【问题描述】:
【问题讨论】:
标签:
python
automated-tests
pytest
【解决方案1】:
据我了解,pytest-dev github 上有一个针对此问题或类似问题的未决项目。
目前,如果可行,您可以在跳过的测试中添加文档(使用文档字符串),以便通过 --collect-only 的详细运行显示原因
这是来自同一 github 的另一个线程的解决方法workaround
@pytest.mark.skip(reason="skipped test")
def test_2():
"""this is skipped as the function does not work as of now"""
pass
Console:
pytest -v -s file.py --collect-only
Result:
collected 5 items
<Module tone.py>
<Function test_2>
this is skipped as the function does not work as of now
<Function test_3>
<Function test_4>
<Function test_5>
<Function test_6>