Skip to content

Commit bf19498

Browse files
authored
fix: Revert report generation to full run (#754)
* fix: Revert report generation to full run * fix: Remove the unserializable cleanup
1 parent 263c1c6 commit bf19498

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

docs/user_guide.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ of a less permissive license, this package is not included as a dependency. If
99
you have this package installed, then ANSI codes will be converted to HTML in
1010
your report.
1111

12+
Report streaming
13+
----------------
14+
15+
In order to stream the result, basically generating the report for each finished test
16+
instead of waiting until the full run is finished, you can set the ``generate_report_on_test``
17+
ini-value:
18+
19+
.. code-block:: ini
20+
21+
[pytest]
22+
generate_report_on_test = True
23+
1224
Creating a self-contained report
1325
--------------------------------
1426

src/pytest_html/basereport.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from pytest_html import __version__
1616
from pytest_html import extras
17-
from pytest_html.util import cleanup_unserializable
1817

1918

2019
class BaseReport:
@@ -49,7 +48,7 @@ def _asset_filename(self, test_id, extra_index, test_index, file_extension):
4948

5049
def _generate_report(self, self_contained=False):
5150
generated = datetime.datetime.now()
52-
test_data = cleanup_unserializable(self._report.data)
51+
test_data = self._report.data
5352
test_data = json.dumps(test_data)
5453
rendered_report = self._template.render(
5554
title=self._report.title,
@@ -239,7 +238,8 @@ def pytest_runtest_logreport(self, report):
239238
dur = test_duration if when == "call" else each.duration
240239
self._process_report(each, dur)
241240

242-
self._generate_report()
241+
if self._config.getini("generate_report_on_test"):
242+
self._generate_report()
243243

244244
def _process_report(self, report, duration):
245245
outcome = _process_outcome(report)

src/pytest_html/plugin.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ def pytest_addoption(parser):
7272
default="result",
7373
help="column to initially sort on.",
7474
)
75+
parser.addini(
76+
"generate_report_on_test",
77+
type="bool",
78+
default=False,
79+
help="the HTML report will be generated after each test "
80+
"instead of at the end of the run.",
81+
)
7582

7683

7784
def pytest_configure(config):

src/pytest_html/util.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
# This Source Code Form is subject to the terms of the Mozilla Public
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4-
import json
54
from functools import partial
6-
from typing import Any
7-
from typing import Dict
85

96
from jinja2 import Environment
107
from jinja2 import FileSystemLoader
@@ -23,18 +20,6 @@
2320
_ansi_styles = []
2421

2522

26-
def cleanup_unserializable(d: Dict[str, Any]) -> Dict[str, Any]:
27-
"""Return new dict with entries that are not json serializable by their str()."""
28-
result = {}
29-
for k, v in d.items():
30-
try:
31-
json.dumps({k: v})
32-
except TypeError:
33-
v = str(v)
34-
result[k] = v
35-
return result
36-
37-
3823
def _read_template(search_paths, template_name="index.jinja2"):
3924
env = Environment(
4025
loader=FileSystemLoader(search_paths),

0 commit comments

Comments
 (0)