Python 如何使用pytest生成测试报告?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29123840/
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 04:06:50  来源:igfitidea点击:

How to generate test report using pytest?

pythonpytest

提问by fhulprogrammer

How can I generate test report using pytest? I searched for it but whatever i got was about coverage report. I tried with this command:

如何使用pytest生成测试报告?我搜索了它,但我得到的都是关于覆盖率报告的。我试过这个命令:

py.test sanity_tests.py --cov=C:\Test\pytest --cov-report=xml

But as parameters represents it generates coverage report not test report. Please help!!

但是作为参数表示它生成覆盖报告而不是测试报告。请帮忙!!

回答by Adam Smith

Ripped from the comments: you can use the --junitxmlargument.

从评论中撕下:您可以使用该--junitxml参数。

$ py.test sample_tests.py --junitxml=C:\path\to\out_report.xml

回答by user3382968

I haven't tried it yet but you can try referring to https://github.com/pytest-dev/pytest-html. A python library that can generate HTML output.

我还没有尝试过,但您可以尝试参考https://github.com/pytest-dev/pytest-html。一个可以生成 HTML 输出的 python 库。

回答by Akansha Tikoo

py.test --html=Report.html 

Here you can specify your python file as well. In this case, when there is no file specified it picks up all the files with a name like 'test_%' present in the directory where the command is run and executes them and generates a report with the name Report.html

您也可以在此处指定您的 python 文件。在这种情况下,当没有指定文件时,它会选择运行命令的目录中存在的所有名称类似于“test_%”的文件并执行它们并生成名为 Report.html 的报告

You can also modify the name of the report accordingly.

您还可以相应地修改报告的名称。