【问题标题】:How to report reasons for skipped tests when running pytest with --collect-only?使用 --collect-only 运行 pytest 时如何报告跳过测试的原因?
【发布时间】:2022-01-11 18:24:50
【问题描述】:

运行 pytest 时,我了解如何使用 report the skip reasons when actually executing tests,但是如何在使用 --collect-only 选项运行 pytest 时报告跳过原因?使用--collect-only -rsx 运行 pytest 不会报告跳过测试的原因。我正在使用 pytest 版本 6.2.2。

【问题讨论】:

    标签: 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-04
      • 2012-11-09
      • 2023-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多