From 57fc54598af4d07d624b88fae3d92e236b600db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jim=20Br=C3=A4nnlund?= Date: Sat, 8 Apr 2023 01:37:36 +0200 Subject: [PATCH] Fix: Add skip marker results to report --- src/pytest_html/basereport.py | 6 ++- testing/test_integration.py | 79 +++++++++++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/src/pytest_html/basereport.py b/src/pytest_html/basereport.py index 7e014f58..611f190e 100644 --- a/src/pytest_html/basereport.py +++ b/src/pytest_html/basereport.py @@ -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) @@ -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("<", "<").replace(">", ">") + "\n") for section in report.sections: header, content = section log.append(f"{' ' + header + ' ':-^80}") diff --git a/testing/test_integration.py b/testing/test_integration.py index 72862bdb..321fd856 100644 --- a/testing/test_integration.py +++ b/testing/test_integration.py @@ -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) @@ -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)