Skip to content

Commit ac30b65

Browse files
committed
Control render using configuration
1 parent 9b7475a commit ac30b65

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

README.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,16 @@ Display options
240240

241241
By default, all rows in the **Results** table will be expanded except those that have :code:`Passed`.
242242

243-
This behavior can be customized with a query parameter: :code:`?collapsed=Passed,XFailed,Skipped`.
243+
This behavior can be customized either with a query parameter: :code:`?collapsed=Passed,XFailed,Skipped`
244+
or by setting the :code:`render_collapsed` in a configuration file (pytest.ini, setup.cfg, etc).
244245

246+
.. code-block:: ini
245247
248+
[pytest]
249+
render_collapsed = True
250+
251+
**NOTE:** Setting :code:`render_collapsed` will, unlike the query parameter, affect all statuses.
252+

246253
Screenshots
247254
-----------
248255

pytest_html/plugin.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ def pytest_addoption(parser):
6262
default=[],
6363
help="append given css file content to report style file.",
6464
)
65+
parser.addini(
66+
"render_collapsed",
67+
type="bool",
68+
default=False,
69+
help="Open the report with all rows collapsed. Useful for very large reports",
70+
)
6571

6672

6773
def pytest_configure(config):
@@ -137,9 +143,12 @@ def __init__(self, outcome, report, logfile, config):
137143
)
138144

139145
if len(cells) > 0:
146+
td_class = "extra"
147+
if self.config.getini("render_collapsed"):
148+
td_class += " collapsed"
140149
self.row_table = html.tr(cells)
141150
self.row_extra = html.tr(
142-
html.td(self.additional_html, class_="extra", colspan=len(cells))
151+
html.td(self.additional_html, class_=td_class, colspan=len(cells))
143152
)
144153

145154
def __lt__(self, other):

testing/test_pytest_html.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,7 @@ def test_extra_image_windows(self, mocker, testdir):
418418
self.test_extra_image(testdir, "image/png", "png")
419419
assert mock_isfile.call_count == 1
420420

421-
@pytest.mark.parametrize(
422-
"mime_type, extension", [("video/mp4", "mp4")],
423-
)
421+
@pytest.mark.parametrize("mime_type, extension", [("video/mp4", "mp4")])
424422
def test_extra_video(self, testdir, mime_type, extension):
425423
content = str(random.random())
426424
testdir.makeconftest(
@@ -882,3 +880,21 @@ def test_pass(utf8):
882880
result, html = run(testdir)
883881
assert result.ret == 0
884882
assert r"\u6d4b\u8bd5\u7528\u4f8b\u540d\u79f0" not in html
883+
884+
@pytest.mark.parametrize("collapsed", [True, False])
885+
def test_collapsed_ini(self, testdir, collapsed):
886+
td_class = "extra"
887+
if collapsed:
888+
td_class += " collapsed"
889+
expected_html = f'<td class="{td_class}" colspan="4">'
890+
testdir.makeini(
891+
f"""
892+
[pytest]
893+
render_collapsed = {collapsed}
894+
"""
895+
)
896+
testdir.makepyfile("def test_fail(): assert False")
897+
result, html = run(testdir)
898+
assert result.ret == 1
899+
assert expected_html in html
900+
assert_results(html, tests=1, passed=0, failed=1)

0 commit comments

Comments
 (0)