使用pytest生成诱惑报告

问题描述 投票:5回答:5

我正在使用py测试诱惑适配器并尝试生成诱惑报告所需的输入数据。但我无法生成任何XML。当我使用py.test sample.py执行py文件时,它确实创建了pycache目录。然后我执行了“诱惑生成-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 allure
5个回答
15
投票

Lavanya。我将尝试解释您必须执行的序列,以生成自动测试的诱惑报告。

  1. 安装点子。下载get-pip.py并执行python get-pip.py。
  2. 通过pip安装pytest和pytest-allure-adapter。执行python -m pip install pytest pytest-allure-adapter
  3. 生成自动测试诱惑xml报告。执行python -m pytest sample.py --alluredir <some directory>
  4. 在<some directory>中出现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报告。在unpacked zip中找到诱惑(针对Windows的allure.bat)。执行allure.bat generate -o <some directory> -v 1.4.0 <some directory>
  7. 在<some directory>中找到index.html并通过浏览器打开它。

*注意<some directory>对于所有步骤都是相同的


1
投票

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

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

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

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


0
投票

现在你必须使用allure-command-line而不是allure-cli来生成html-report,因为第二个被弃用了。


0
投票

通过诱惑生成报告的方法非常简单。

首先安装诱惑。 (1)allure-pytest 2.6.0(2)allure-python-commons 2.6.0

然后,如果您无法生成报告,请按照以下步骤操作..步骤-1(使用pytest)pytest test_xyz.py --alluredir =您要保存报告的路径。

step -2 allure serve report_path

如果仍然显示诱惑是不被认可的命令(blah -blah)

然后使用npm插件和下面的命令安装诱惑

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

然后再次按照步骤2,然后一个服务器将启动,您可以看到诱惑报告。


0
投票

这是我发现的工作 -

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

然后执行保存报告的以下行 -

python3 -m allure serve \Report

这将在默认浏览器中打开倾城度报告。

© www.soinside.com 2019 - 2024. All rights reserved.