From e494d1a335e0ac7ddef227a49437f11958eda5cd Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 21 Nov 2023 20:23:29 +1000 Subject: [PATCH] Generate markdown report from Python tests too --- python/testing/__init__.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/python/testing/__init__.py b/python/testing/__init__.py index ba80d16405f..028f87ffbb6 100644 --- a/python/testing/__init__.py +++ b/python/testing/__init__.py @@ -73,11 +73,14 @@ class QgisTestCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.report = '' + cls.markdown_report = '' @classmethod def tearDownClass(cls): if cls.report: cls.write_local_html_report(cls.report) + if cls.markdown_report: + cls.write_local_markdown_report(cls.markdown_report) @classmethod def control_path_prefix(cls) -> Optional[str]: @@ -127,6 +130,24 @@ class QgisTestCase(unittest.TestCase): if not QgisTestCase.is_ci_run(): QDesktopServices.openUrl(QUrl.fromLocalFile(report_file)) + @classmethod + def write_local_markdown_report(cls, report: str): + report_dir = QgsRenderChecker.testReportDir() + if not report_dir.exists(): + QDir().mkpath(report_dir.path()) + + report_file = report_dir.filePath('summary.md') + + # only append to existing reports if running under CI + if cls.is_ci_run() or \ + os.environ.get("QGIS_APPEND_TO_TEST_REPORT") == 'true': + file_mode = 'ta' + else: + file_mode = 'wt' + + with open(report_file, file_mode, encoding='utf-8') as f: + f.write(report) + @classmethod def image_check(cls, name: str, @@ -156,6 +177,11 @@ class QgisTestCase(unittest.TestCase): cls.report += f"

Render {name}

\n" cls.report += checker.report() + markdown = checker.markdownReport() + if markdown: + cls.markdown_report += "## {}\n\n".format(name) + cls.markdown_report += markdown + return result @classmethod @@ -178,6 +204,11 @@ class QgisTestCase(unittest.TestCase): cls.report += f"

Render {name}

\n" cls.report += checker.report() + markdown = checker.markdownReport() + if markdown: + cls.markdown_report += "## {}\n\n".format(name) + cls.markdown_report += markdown + return result @classmethod @@ -193,6 +224,12 @@ class QgisTestCase(unittest.TestCase): if not result: cls.report += f"

Render {name}

\n" cls.report += checker.report() + + markdown = checker.markdownReport() + if markdown: + cls.markdown_report += "## {}\n\n".format(name) + cls.markdown_report += markdown + return result def assertLayersEqual(self, layer_expected, layer_result, **kwargs):