Reputation: 669
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.
Upvotes: 49
Views: 96203
Reputation: 979
You can use a pytest plugin 'pytest-html' for generating html reports which can be forwarded to different teams as well
First install the plugin:
$ pip install pytest-html
Second, just run your tests with this command:
$ pytest --html=report.html
You can also make use of the hooks provided by the plugin in your code.
import pytest
from py.xml import html
def pytest_html_report_title(report)
report.title = "My very own title!"
Reference: https://pypi.org/project/pytest-html/
Upvotes: 10
Reputation: 13
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.
Upvotes: -2
Reputation: 416
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.
Upvotes: -1
Reputation: 54183
Ripped from the comments: you can use the --junitxml
argument.
$ py.test sample_tests.py --junitxml=C:\path\to\out_report.xml
Upvotes: 84