How to generate test report using pytest?

2020-07-02 08:38发布

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:

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!!

标签: python pytest
3条回答
看我几分像从前
2楼-- · 2020-07-02 08:57
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

You can also modify the name of the report accordingly.

查看更多
小情绪 Triste *
3楼-- · 2020-07-02 09:01

Ripped from the comments: you can use the --junitxml argument.

$ py.test sample_tests.py --junitxml=C:\path\to\out_report.xml
查看更多
家丑人穷心不美
4楼-- · 2020-07-02 09:09

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.

查看更多
登录 后发表回答