Python 使用 pytest 生成诱惑报告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26434791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:28:09  来源:igfitidea点击:

Generating allure report using pytest

pythonpytestallure

提问by Lavanya

I am using py test allure adaptor and trying to generate input data required for allure report. But I am not able to generate any XML's. When I execute the py file using py.test sample.py, it did create pycachedir. Then I executed "allure generate -v 1.3.9 C:\allurereports" (This is the dir where I had the sample.py). It did create an allure html report but no of test cases was 0. No details were present.

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

The sample.py(it is same as given in the example)

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

Here's the py.test command used: py.test sample.py --allure_features=feature1,feature2

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

Can anybody help me how to generate an allure report from the file? What are the commands to execute?

任何人都可以帮助我如何从文件中生成诱惑报告?要执行的命令是什么?

回答by Dmitry Baev

You should specify directory with your test data(the directory which contains -testsuite.xmlfiles), not a test directory.

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

You can use py.test --alluredir [path_to_report_dir]to sprcify it.

您可以使用py.test --alluredir [path_to_report_dir]srcify 它。

PS. Make sure you use right version of allure (latest pytest adapter supports only allure 1.4.*).

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

For more information see https://github.com/allure-framework/allure-pythonand https://github.com/allure-framework/allure-cli

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

回答by George Regentov

Lavanya. I'll try to explain the sequence you must to perform to generate allure report of autotest.

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

  1. Install pip. Download get-pip.py and perform python get-pip.py.

  2. Install pytestand pytest-allure-adaptorvia pip. Perform python -m pip install pytest pytest-allure-adaptor

  3. Generate autotest allure xml report. Perform python -m pytest sample.py --alluredir <some directory>

  4. In <some directory> appear xml autotest report, which contain results of sample.py tests. Let's make beauty html report via an allure-cli tool.

  5. Install allure-cli. Download last version of allure-cli. allure-cli requires java. allure-cli doesn't require installation, just unpack and use it.

  6. Generate html report. Find allure (allure.bat for Windows) in unpacked zip. Perform allure.bat generate -o <some directory> -v 1.4.0 <some directory>

  7. Find index.html in <some directory> and open it via a browser.

  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 <some directory>

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

  5. 安装 allure-cli。下载allure-cli 的最新版本。allure-cli 需要 java。allure-cli 不需要安装,直接解压使用即可

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

  7. 在 <some directory> 中找到 index.html 并通过浏览器打开它。

*Note<some directory> the same for all steps

*注意<某个目录> 对于所有步骤都相同

回答by Ustin

now you must use allure-command-line instead of allure-cli to generate html-report, cause the second one is deprecated.

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

回答by jayesh

There is a very simple way to generate reports via allure:

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

first, install allure:

首先,安装诱惑:

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

Then, if you are unable to generate the reports, follow below steps:

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

  1. (using pytest)

    pytest test_xyz.py --alluredir=path_where_you_want_to_save_reports
    
  2. allure serve report_path
    
  1. (使用pytest)

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

If it is still showing allure is not recognized command (blah -blah), then install allure using npm plugin with below command:

如果它仍然显示诱惑无法识别命令(blah -blah),则使用 npm 插件安装 allure 并使用以下命令:

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

then follow step (2) again, then one server will start and you will be able to see allure reports.

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

回答by Shivam Bharadwaj

This is something that I found working -

这是我发现工作的东西-

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

Then perform the below line where you saved your report -

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

python3 -m allure serve \Report

This will open up the allure report in your default browser.

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