Skip to content
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
6 changes: 4 additions & 2 deletions src/pytest_html/basereport.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def add_test(self, test_data, report, remove_log=False):
self.update_test_log(report)

# passed "setup" and "teardown" are not added to the html
if report.when == "call" or _is_error(report):
if report.when == "call" or (
report.when in ["setup", "teardown"] and report.outcome != "passed"
):
if not remove_log:
processed_logs = _process_logs(report)
test_data["log"] = _handle_ansi(processed_logs)
Expand Down Expand Up @@ -331,7 +333,7 @@ def _is_error(report):
def _process_logs(report):
log = []
if report.longreprtext:
log.append(report.longreprtext + "\n")
log.append(report.longreprtext.replace("<", "&lt;").replace(">", "&gt;") + "\n")
for section in report.sections:
header, content = section
log.append(f"{' ' + header + ' ':-^80}")
Expand Down
79 changes: 76 additions & 3 deletions testing/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,40 @@ def test_skip(self, pytester):
f"""
import pytest
def test_skip():
pytest.skip('{reason}')
pytest.skip("{reason}")
"""
)
page = run(pytester)
assert_results(page, skipped=1, total_tests=0)

log = get_text(page, ".summary div[class='log']")
assert_that(log).contains(reason)

def test_skip_function_marker(self, pytester):
reason = str(random.random())
pytester.makepyfile(
f"""
import pytest
@pytest.mark.skip(reason="{reason}")
def test_skip():
assert True
"""
)
page = run(pytester)
assert_results(page, skipped=1, total_tests=0)

log = get_text(page, ".summary div[class='log']")
assert_that(log).contains(reason)

def test_skip_class_marker(self, pytester):
reason = str(random.random())
pytester.makepyfile(
f"""
import pytest
@pytest.mark.skip(reason="{reason}")
class TestSkip:
def test_skip():
assert True
"""
)
page = run(pytester)
Expand All @@ -213,20 +246,60 @@ def test_xfail(self, pytester):
f"""
import pytest
def test_xfail():
pytest.xfail('{reason}')
pytest.xfail("{reason}")
"""
)
page = run(pytester)
assert_results(page, xfailed=1)
assert_that(get_log(page)).contains(reason)

def test_xfail_function_marker(self, pytester):
reason = str(random.random())
pytester.makepyfile(
f"""
import pytest
@pytest.mark.xfail(reason="{reason}")
def test_xfail():
assert False
"""
)
page = run(pytester)
assert_results(page, xfailed=1)
assert_that(get_log(page)).contains(reason)

def test_xfail_class_marker(self, pytester):
pytester.makepyfile(
"""
import pytest
@pytest.mark.xfail(reason="broken")
class TestXFail:
def test_xfail(self):
assert False
"""
)
page = run(pytester)
assert_results(page, xfailed=1)

def test_xpass(self, pytester):
pytester.makepyfile(
"""
import pytest
@pytest.mark.xfail()
def test_xpass():
pass
assert True
"""
)
page = run(pytester)
assert_results(page, xpassed=1)

def test_xpass_class_marker(self, pytester):
pytester.makepyfile(
"""
import pytest
@pytest.mark.xfail()
class TestXPass:
def test_xpass(self):
assert True
"""
)
page = run(pytester)
Expand Down