Skip to content

Commit 89746e3

Browse files
authored
Fix: Add skip marker results to report (#636)
1 parent f1bd1eb commit 89746e3

File tree

2 files changed

+80
-5
lines changed

2 files changed

+80
-5
lines changed

src/pytest_html/basereport.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ def add_test(self, test_data, report, remove_log=False):
8484
self.update_test_log(report)
8585

8686
# passed "setup" and "teardown" are not added to the html
87-
if report.when == "call" or _is_error(report):
87+
if report.when == "call" or (
88+
report.when in ["setup", "teardown"] and report.outcome != "passed"
89+
):
8890
if not remove_log:
8991
processed_logs = _process_logs(report)
9092
test_data["log"] = _handle_ansi(processed_logs)
@@ -338,7 +340,7 @@ def _is_error(report):
338340
def _process_logs(report):
339341
log = []
340342
if report.longreprtext:
341-
log.append(report.longreprtext + "\n")
343+
log.append(report.longreprtext.replace("<", "&lt;").replace(">", "&gt;") + "\n")
342344
for section in report.sections:
343345
header, content = section
344346
log.append(f"{' ' + header + ' ':-^80}")

testing/test_integration.py

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,40 @@ def test_skip(self, pytester):
192192
f"""
193193
import pytest
194194
def test_skip():
195-
pytest.skip('{reason}')
195+
pytest.skip("{reason}")
196+
"""
197+
)
198+
page = run(pytester)
199+
assert_results(page, skipped=1, total_tests=0)
200+
201+
log = get_text(page, ".summary div[class='log']")
202+
assert_that(log).contains(reason)
203+
204+
def test_skip_function_marker(self, pytester):
205+
reason = str(random.random())
206+
pytester.makepyfile(
207+
f"""
208+
import pytest
209+
@pytest.mark.skip(reason="{reason}")
210+
def test_skip():
211+
assert True
212+
"""
213+
)
214+
page = run(pytester)
215+
assert_results(page, skipped=1, total_tests=0)
216+
217+
log = get_text(page, ".summary div[class='log']")
218+
assert_that(log).contains(reason)
219+
220+
def test_skip_class_marker(self, pytester):
221+
reason = str(random.random())
222+
pytester.makepyfile(
223+
f"""
224+
import pytest
225+
@pytest.mark.skip(reason="{reason}")
226+
class TestSkip:
227+
def test_skip():
228+
assert True
196229
"""
197230
)
198231
page = run(pytester)
@@ -216,20 +249,60 @@ def test_xfail(self, pytester):
216249
f"""
217250
import pytest
218251
def test_xfail():
219-
pytest.xfail('{reason}')
252+
pytest.xfail("{reason}")
220253
"""
221254
)
222255
page = run(pytester)
223256
assert_results(page, xfailed=1)
224257
assert_that(get_log(page)).contains(reason)
225258

259+
def test_xfail_function_marker(self, pytester):
260+
reason = str(random.random())
261+
pytester.makepyfile(
262+
f"""
263+
import pytest
264+
@pytest.mark.xfail(reason="{reason}")
265+
def test_xfail():
266+
assert False
267+
"""
268+
)
269+
page = run(pytester)
270+
assert_results(page, xfailed=1)
271+
assert_that(get_log(page)).contains(reason)
272+
273+
def test_xfail_class_marker(self, pytester):
274+
pytester.makepyfile(
275+
"""
276+
import pytest
277+
@pytest.mark.xfail(reason="broken")
278+
class TestXFail:
279+
def test_xfail(self):
280+
assert False
281+
"""
282+
)
283+
page = run(pytester)
284+
assert_results(page, xfailed=1)
285+
226286
def test_xpass(self, pytester):
227287
pytester.makepyfile(
228288
"""
229289
import pytest
230290
@pytest.mark.xfail()
231291
def test_xpass():
232-
pass
292+
assert True
293+
"""
294+
)
295+
page = run(pytester)
296+
assert_results(page, xpassed=1)
297+
298+
def test_xpass_class_marker(self, pytester):
299+
pytester.makepyfile(
300+
"""
301+
import pytest
302+
@pytest.mark.xfail()
303+
class TestXPass:
304+
def test_xpass(self):
305+
assert True
233306
"""
234307
)
235308
page = run(pytester)

0 commit comments

Comments
 (0)