Skip to content

Control render using configuration #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,15 @@ Display options

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

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

.. code-block:: ini

[pytest]
render_collapsed = True

**NOTE:** Setting :code:`render_collapsed` will, unlike the query parameter, affect all statuses.

Screenshots
-----------
Expand Down
11 changes: 10 additions & 1 deletion pytest_html/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def pytest_addoption(parser):
default=[],
help="append given css file content to report style file.",
)
parser.addini(
"render_collapsed",
type="bool",
default=False,
help="Open the report with all rows collapsed. Useful for very large reports",
)


def pytest_configure(config):
Expand Down Expand Up @@ -137,9 +143,12 @@ def __init__(self, outcome, report, logfile, config):
)

if len(cells) > 0:
td_class = "extra"
if self.config.getini("render_collapsed"):
td_class += " collapsed"
self.row_table = html.tr(cells)
self.row_extra = html.tr(
html.td(self.additional_html, class_="extra", colspan=len(cells))
html.td(self.additional_html, class_=td_class, colspan=len(cells))
)

def __lt__(self, other):
Expand Down
22 changes: 19 additions & 3 deletions testing/test_pytest_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,7 @@ def test_extra_image_windows(self, mocker, testdir):
self.test_extra_image(testdir, "image/png", "png")
assert mock_isfile.call_count == 1

@pytest.mark.parametrize(
"mime_type, extension", [("video/mp4", "mp4")],
)
@pytest.mark.parametrize("mime_type, extension", [("video/mp4", "mp4")])
def test_extra_video(self, testdir, mime_type, extension):
content = str(random.random())
testdir.makeconftest(
Expand Down Expand Up @@ -882,3 +880,21 @@ def test_pass(utf8):
result, html = run(testdir)
assert result.ret == 0
assert r"\u6d4b\u8bd5\u7528\u4f8b\u540d\u79f0" not in html

@pytest.mark.parametrize("collapsed", [True, False])
def test_collapsed_ini(self, testdir, collapsed):
td_class = "extra"
if collapsed:
td_class += " collapsed"
expected_html = f'<td class="{td_class}" colspan="4">'
testdir.makeini(
f"""
[pytest]
render_collapsed = {collapsed}
"""
)
testdir.makepyfile("def test_fail(): assert False")
result, html = run(testdir)
assert result.ret == 1
assert expected_html in html
assert_results(html, tests=1, passed=0, failed=1)