【问题标题】:Generating allure report using pytest使用 pytest 生成魅力报告
【发布时间】:2014-12-13 14:44:02
【问题描述】:

我正在使用 py test allure 适配器并尝试生成 allure 报告所需的输入数据。但我无法生成任何 XML。当我使用 py.test sample.py 执行 py 文件时,它确实创建了 pycache 目录。然后我执行了“allure generate -v 1.3.9 C:\allurereports”(这是我有sample.py的目录)。它确实创建了一个魅力 html 报告,但没有测试用例为 0。没有详细信息。

sample.py(与示例中给出的相同)

import allure


@allure.feature('Feature1')
@allure.story('Story1')
def test_minor():
    assert False


@allure.feature('Feature2')
@allure.story('Story2', 'Story3')
@allure.story('Story4')
class TestBar:

    # will have 'Feature2 and Story2 and Story3 and Story4'
    def test_bar(self):
        pass

这是使用的 py.test 命令: py.test sample.py --allure_features=feature1,feature2

谁能帮助我如何从文件中生成诱惑报告?要执行的命令是什么?

【问题讨论】:

    标签: python pytest allure


    【解决方案1】:

    拉瓦尼亚。 我将尝试解释您必须执行的顺序以生成自动测试的魅力报告。

    1. 安装 pip。下载 get-pip.py 并执行 python get-pip.py

    2. 通过 pip 安装 pytestpytest-allure-adaptor。执行 python -m pip install pytest pytest-allure-adaptor

    3. 生成自动测试诱惑 xml 报告。执行 python -m pytest sample.py --alluredir

    4. 中出现xml自动测试报告,其中包含sample.py测试的结果。让我们通过 allure-cli 工具制作美颜 html 报告。

    5. 安装 allure-cli。下载last version of allure-cli。 allure-cli 需要 java。 allure-cli 不需要安装,just unpack and use it.

    6. 生成 html 报告。在解压后的 zip 中找到 allure (allure.bat for Windows)。执行 allure.bat generate -o -v 1.4.0

    7. 中找到index.html并通过浏览器打开。

    *注意 所有步骤都相同

    【讨论】:

    • 我在安装包pytest-allure-adaptor时遇到了一些问题。依赖lxml,最后一个自动先安装。请参阅Requires Distributions 以获取依赖项。即,lxml 安装引起了问题。根据thisthis,将包libxml2-devlibxslt1-dev安装到我的系统中,解决了问题。
    【解决方案2】:

    有一种非常简单的方法可以通过 allure 生成报告:

    首先,安装 allure:

    1. allure-pytest 2.6.0
    2. allure-python-commons 2.6.0

    然后,如果您无法生成报告,请按照以下步骤操作:

    1. (使用 pytest)

      pytest test_xyz.py --alluredir=path_where_you_want_to_save_reports
      
    2. allure serve report_path
      

    如果仍然显示 allure is not Recogniz 命令 (blah -blah),则使用 npm 插件安装 allure,命令如下:

    npm install -g allure-commandline --save-dev
    

    然后再次执行步骤(2),然后将启动一个服务器,您将能够看到诱惑报告。

    【讨论】:

    • 我正在尝试使用 allure-commons 而不是 Pytest 生成报告。您能否分享相同的命令来创建 XML 和 Json 诱惑报告文件?
    【解决方案3】:

    您应该指定包含测试数据的目录(包含 -testsuite.xml 文件的目录),不是测试目录

    您可以使用py.test --alluredir [path_to_report_dir] 来指定它。

    PS。确保使用正确版本的 allure(最新的 pytest 适配器仅支持 allure 1.4.*)。

    有关更多信息,请参阅https://github.com/allure-framework/allure-pythonhttps://github.com/allure-framework/allure-cli

    【讨论】:

      【解决方案4】:

      这是我发现的工作 -

      python3 -m pytest [your_test_class_name] --alluredir \Report
      

      然后在您保存报告的位置执行以下行 -

      python3 -m allure serve \Report
      

      这将在您的默认浏览器中打开魅力报告。

      【讨论】:

        【解决方案5】:

        现在您必须使用 allure-command-line 而不是 allure-cli 来生成 html-report,因为不推荐使用第二个。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-10-13
          • 2020-05-31
          • 2023-03-31
          • 1970-01-01
          • 1970-01-01
          • 2016-12-13
          • 2017-07-14
          • 1970-01-01
          相关资源
          最近更新 更多