Skip to content

Fix collapsable bug #268

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 1 commit into from
Feb 25, 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
7 changes: 4 additions & 3 deletions pytest_html/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ def __init__(self, outcome, report, logfile, config):
)

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

def __lt__(self, other):
Expand Down
4 changes: 3 additions & 1 deletion pytest_html/resources/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ function add_collapse() {
var collapsed = get_query_parameter('collapsed') || 'Passed';
var extras = elem.parentNode.nextElementSibling;
var expandcollapse = document.createElement("span");
if (collapsed.includes(elem.innerHTML)) {
if (extras.classList.contains("collapsed")) {
expandcollapse.classList.add("expander")
} else if (collapsed.includes(elem.innerHTML)) {
extras.classList.add("collapsed");
expandcollapse.classList.add("expander");
} else {
Expand Down
26 changes: 16 additions & 10 deletions testing/test_pytest_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,20 +881,26 @@ def test_pass(utf8):
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">'
@pytest.mark.parametrize("is_collapsed", [True, False])
def test_collapsed(self, testdir, is_collapsed):
collapsed_html = '<tr class="collapsed">'
expected_count = 2 if is_collapsed else 0
testdir.makeini(
f"""
[pytest]
render_collapsed = {collapsed}
render_collapsed = {is_collapsed}
"""
)
testdir.makepyfile(
"""
def test_fail():
assert False

def test_pass():
assert True
"""
)
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)
assert len(re.findall(collapsed_html, html)) == expected_count
assert_results(html, tests=2, passed=1, failed=1)