【问题标题】:auto generation of html report in pytest without commanline arguments在没有命令行参数的 pytest 中自动生成 html 报告
【发布时间】:2019-06-05 12:20:36
【问题描述】:

我正在使用 pytest-html 插件。 在命令行中传递参数时会生成 html 报告。 需要自动创建html报告,并且在终端显示html报告链接。

【问题讨论】:

    标签: report pytest pytest-html


    【解决方案1】:

    您可以将cmdline参数放在根目录下的pytest.ini文件中

    $ cat pytest.ini
    [pytest]
    addopts = --html=report.html --self-contained-html
    

    【讨论】:

      【解决方案2】:

      您可以通过在文件conftest.py 中编写pytest_cmdline_preparse() 挂钩来完成此操作

      def pytest_cmdline_preparse(config, args):
          html_file = func_to_generate_html_filename()
          print('HTML report file:', html_file)
          args.extend(['--html', html_file, '--self-contained-html'])
      

      【讨论】:

        【解决方案3】:

        另一种选择,就像 Nizar 的回答一样

        def pytest_cmdline_preparse(config, args):
            config.option.htmlpath = "my-report.html"
            config.option.self_contained_html = True
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-07-01
          • 1970-01-01
          • 2021-05-21
          • 1970-01-01
          相关资源
          最近更新 更多