[Python] Generate HTML and XML report of tests using pytest

Discussão em 'Python' iniciado por Stack, Setembro 6, 2025.

  1. Stack

    Stack Membro Participativo

    I need to generate both XML and HTML report of the tests that I've written using pytest. Below is my project setup and code

    main.py:

    def main():
    print("Hello from pytest-html-report-generator!")

    if __name__ == "__main__":
    main()


    test_addition.py:

    import pytest

    def test_addition():
    assert 1 + 1 == 3


    pyproject.toml:

    pytest[project]
    name = "pytest-html-report-generator"
    version = "0.1.0"
    description = "Add your description here"
    readme = "README.md"
    requires-python = ">=3.12"
    dependencies = [
    "pytest>=8.4.2",
    "pytest-html>=4.1.1",
    ]


    Error:

    pytest --junit-xml=report.xml 4 err | at 09:46:24
    /usr/lib/python3/dist-packages/_pytest/config/__init__.py:331: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
    Plugin: helpconfig, Hook: pytest_cmdline_parse
    UsageError: /home/harry/pytest_html_report_generator/pyproject.toml: Expected '=' after a key in a key/value pair (at line 1, column 7)
    For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning
    config = pluginmanager.hook.pytest_cmdline_parse(
    ERROR: /home/harry/pytest_html_report_generator/pyproject.toml: Expected '=' after a key in a key/value pair (at line 1, column 7)


    pytest --html=report.html 4 err | at 09:45:07
    /usr/lib/python3/dist-packages/_pytest/config/__init__.py:331: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
    Plugin: helpconfig, Hook: pytest_cmdline_parse
    UsageError: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
    pytest: error: unrecognized arguments: --html=report.html
    inifile: None
    rootdir: /home/harry/pytest_html_report_generator
    For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning
    config = pluginmanager.hook.pytest_cmdline_parse(
    ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
    pytest: error: unrecognized arguments: --html=report.html
    inifile: None
    rootdir: /home/harry/pytest_html_report_generator

    Continue reading...

Compartilhe esta Página