Control render using configuration
This commit is contained in:
parent
9b7475a185
commit
ac30b65c34
|
@ -240,9 +240,16 @@ 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
|
||||
-----------
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
@ -137,9 +143,12 @@ class HTMLReport:
|
|||
)
|
||||
|
||||
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):
|
||||
|
|
|
@ -418,9 +418,7 @@ class TestHTML:
|
|||
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(
|
||||
|
@ -882,3 +880,21 @@ class TestHTML:
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue