close

How to generate test report using pytest?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to generate test report using pytest in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to generate test report using pytest?

  1. How to generate test report using pytest?

    Ripped from the comments: you can use the --junitxml argument.
    $ py.test sample_tests.py --junitxml=C:\path\to\out_report.xml

  2. generate test report using pytest

    Ripped from the comments: you can use the --junitxml argument.
    $ py.test sample_tests.py --junitxml=C:\path\to\out_report.xml

Method 1

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

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

Method 2

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

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read