Skip to content

Performance regression in pytest-html 4.0.0 #751

Closed
@akhilramkee

Description

@akhilramkee
  • There seems to be significant overhead introduced to execution of pytest by pytest-html 4

pytest-html 4 (Takes 6s)

pytest tests_sample.py --html ~/tmp/results.html
========================================================================================= test session starts =========================================================================================
platform darwin -- Python 3.11.4, pytest-7.0.1, pluggy-1.3.0
plugins: metadata-3.0.0, html-4.0.0
collected 1000 items

tests_sample.py ............................................................................................................................................................................... [ 17%]
............................................................................................................................................................................................... [ 36%]
............................................................................................................................................................................................... [ 55%]
............................................................................................................................................................................................... [ 74%]
............................................................................................................................................................................................... [ 93%]
.............................................................                                                                                                                                   [100%]

------------------------------------------------------------------- Generated html report: file:///Users/user/tmp/results.html -------------------------------------------------------------------
======================================================================================== 1000 passed in 6.28s =========================================================================================

pytest-html 3.2 (Takes 1s)

pytest tests_sample.py --html ~/tmp/results.html
========================================================================================= test session starts =========================================================================================
platform darwin -- Python 3.11.4, pytest-7.0.1, pluggy-1.3.0
plugins: html-3.2.0, metadata-3.0.0
collected 1000 items

tests_sample.py ............................................................................................................................................................................... [ 17%]
............................................................................................................................................................................................... [ 36%]
............................................................................................................................................................................................... [ 55%]
............................................................................................................................................................................................... [ 74%]
............................................................................................................................................................................................... [ 93%]
.............................................................

-------------------------------------------------------------------- generated html file: file:///Users/user/tmp/results.html --------------------------------------------------------------------
======================================================================================== 1000 passed in 1.10s =========================================================================================

To reproduce:

File structure:

pytest_html_reproducer/
├── __init__.py
└── tests/
    └── tests_sample.py

tests_sample.py

import pytest
import random

random_values = [int(random.random() * 1e4) for _ in range(1000)]

@pytest.mark.parametrize("val", random_values)
def test_a(val):
    assert 1

This slowness with pytest-html 4.0.0 is more pronounced in larger test suites (100K tests - tweaking the random_values count also shows the same), as the test execution took a 14+ hours with 90% of the execution time being taken by pytest-html to render the results.

Profile sample: Link

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions