From 584029e897593e89e5d7266da9c8b0628da51dfb Mon Sep 17 00:00:00 2001 From: laz Date: Mon, 7 Sep 2026 11:23:19 +0800 Subject: [PATCH 1/4] Add option --puls-no-html --- pytest_html_plus/plugin.py | 106 ++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 43 deletions(-) diff --git a/pytest_html_plus/plugin.py b/pytest_html_plus/plugin.py index 9c3b03c..8226a91 100644 --- a/pytest_html_plus/plugin.py +++ b/pytest_html_plus/plugin.py @@ -37,6 +37,7 @@ "json-report": {"flag": "--json-report", "kind": "value"}, "capture-screenshots": {"flag": "--capture-screenshots", "kind": "value"}, "html-output": {"flag": "--html-output", "kind": "value"}, + "plus-no-html": {"flag": "--plus-no-html", "kind": "bool"}, "screenshots": {"flag": "--screenshots", "kind": "value"}, "plus-email": {"flag": "--plus-email", "kind": "bool"}, "should-open-report": {"flag": "--should-open-report", "kind": "value"}, @@ -338,30 +339,31 @@ def pytest_sessionfinish(session, exitstatus): output_path=json_path, ) - script_path = os.path.join(os.path.dirname(__file__), "generate_html_report.py") - if not os.path.exists(script_path): - logger.warning( - f"Report generation script not found at {script_path}. " - f"Skipping HTML report generation." - ) - return + if not session.config.getoption("--plus-no-html"): + script_path = os.path.join(os.path.dirname(__file__), "generate_html_report.py") + if not os.path.exists(script_path): + logger.warning( + f"Report generation script not found at {script_path}. " + f"Skipping HTML report generation." + ) + return - try: - subprocess.run( - [ - sys.executable, - script_path, - "--report", - json_path, - "--screenshots", - screenshots_path, - "--output", - html_output, - ], - check=True, - ) - except Exception as e: - raise RuntimeError(f"Exception during HTML report generation: {e}") from e + try: + subprocess.run( + [ + sys.executable, + script_path, + "--report", + json_path, + "--screenshots", + screenshots_path, + "--output", + html_output, + ], + check=True, + ) + except Exception as e: + raise RuntimeError(f"Exception during HTML report generation: {e}") from e # ---- Generate XML ---- if session.config.getoption("--generate-xml"): @@ -378,7 +380,9 @@ def pytest_sessionfinish(session, exitstatus): except Exception: logger.warning("Could not clean up screenshots directory") - if session.config.getoption("--plus-email"): + if session.config.getoption("--plus-email") and not session.config.getoption( + "--plus-no-html" + ): try: config = load_email_env() config["report_path"] = html_output @@ -387,12 +391,13 @@ def pytest_sessionfinish(session, exitstatus): except Exception as e: raise RuntimeError(f"Failed to send email: {e}") from e - # ---- Open report (controller only) ---- - open_html_report( - report_path=os.path.join(html_output, "report.html"), - json_path=json_path, - config=session.config, - ) + if not session.config.getoption("--plus-no-html"): + # ---- Open report (controller only) ---- + open_html_report( + report_path=os.path.join(html_output, "report.html"), + json_path=json_path, + config=session.config, + ) def pytest_sessionstart(session): @@ -431,18 +436,31 @@ def pytest_load_initial_conftests(args): def pytest_addoption(parser): group = parser.getgroup("pytest-html-plus", "pytest-html-plus reporting options") + # General options group.addoption( PROFILE_OPTION, action="store", default=None, help="Load pytest-html-plus options from a named profile in pyproject.toml", ) + group.addoption( + OUTPUT_OPTION, + action="store", + default="all", + choices=OUTPUT_CHOICES, + help=( + "Include captured stdout/stderr in reports: all (default), " + "failed-only, or none" + ), + ) group.addoption( "--json-report", action="store", default="final_report.json", help="Name of the JSON report file generated alongside the HTML report", ) + + # Screenshot options group.addoption( "--capture-screenshots", action="store", @@ -450,24 +468,16 @@ def pytest_addoption(parser): choices=["failed", "all", "none"], help="Capture screenshots: failed (default), all, or none", ) - group.addoption( - OUTPUT_OPTION, - action="store", - default="all", - choices=OUTPUT_CHOICES, - help=( - "Include captured stdout/stderr in reports: all (default), " - "failed-only, or none" - ), - ) - group.addoption("--html-output", default="report_output") group.addoption("--screenshots", default="screenshots") + + # HTML options group.addoption( - "--plus-email", + "--plus-no-html", action="store_true", default=False, - help="Send HTML test report via email after test run", + help="Disable HTML report generation from the final JSON report", ) + group.addoption("--html-output", default="report_output") group.addoption( "--should-open-report", action="store", @@ -475,6 +485,14 @@ def pytest_addoption(parser): choices=["always", "failed", "never"], help="When to open the HTML report: always, failed, or never (default: failed)", ) + group.addoption( + "--plus-email", + action="store_true", + default=False, + help="Send HTML test report via email after test run", + ) + + # XML options group.addoption( "--generate-xml", action="store_true", @@ -487,6 +505,8 @@ def pytest_addoption(parser): default=None, help="Name of the XML report file generated alongside the HTML report (used with --generate-xml)", # noqa ) + + # Other options group.addoption( "--git-branch", action="store", From ef35b734e9a2b3dc2b698f0da47fcd7fab5bde89 Mon Sep 17 00:00:00 2001 From: laz Date: Mon, 7 Sep 2026 11:32:27 +0800 Subject: [PATCH 2/4] Add description for --plus-no-htm option --- CHANGELOG.md | 4 ++++ docs/cli/cli.rst | 28 ++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1ae926..1c4a8b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ Versions follow [Semantic Versioning](https://semver.org/). _Changes merged to `main` but not yet released._ +### Added + +* Add --puls-no-html to skip generate HTML report. + --- ## [1.2.0] — 2026-08-11 diff --git a/docs/cli/cli.rst b/docs/cli/cli.rst index 5cd230b..10180b7 100644 --- a/docs/cli/cli.rst +++ b/docs/cli/cli.rst @@ -13,6 +13,14 @@ Overview - **Description** - **Default** - **Use Case** + * - ``--plus-profile`` + - Load a named profile from ``pyproject.toml`` + - ``None`` + - Reuse a standard reporting configuration across local runs and CI + * - ``--plus-output`` + - Control which captured stdout/stderr streams are included in reports + - ``all`` + - Reduce report size by omitting output from passing tests or all tests * - ``--json-report`` - Name of the JSON report file generated alongside the HTML report - ``final_report.json`` @@ -21,26 +29,22 @@ Overview - When to capture screenshots - ``failed`` - Useful in flaky UI tests to get screenshots on failure - * - ``--plus-output`` - - Control which captured stdout/stderr streams are included in reports - - ``all`` - - Reduce report size by omitting output from passing tests or all tests + * - ``--puls-no-html`` + - Disable HTML report generation + - False + - Useful when integrating * - ``--html-output`` - Directory for HTML output - ``report_output`` - Customize output directory per CI job - * - ``--plus-profile`` - - Load a named profile from ``pyproject.toml`` - - ``None`` - - Reuse a standard reporting configuration across local runs and CI - * - ``--plus-email`` - - Send HTML report via email - - ``False`` - - Enable in scheduled test runs (nightly builds) * - ``--should-open-report`` - Auto-open report after run - ``failed`` - Open only when failures occur locally + * - ``--plus-email`` + - Send HTML report via email + - ``False`` + - Enable in scheduled test runs (nightly builds) * - ``--generate-xml`` - Generate a combined XML for CI/coverage - ``False`` From 57153406e1105ed8cc1a68c36f6ae2081ffd9109 Mon Sep 17 00:00:00 2001 From: laz Date: Tue, 8 Sep 2026 10:05:05 +0800 Subject: [PATCH 3/4] Fix spelling error --- CHANGELOG.md | 2 +- docs/cli/cli.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c4a8b3..c8e0712 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ _Changes merged to `main` but not yet released._ ### Added -* Add --puls-no-html to skip generate HTML report. +* Add --plus-no-html to skip generate HTML report. --- diff --git a/docs/cli/cli.rst b/docs/cli/cli.rst index 10180b7..38e2724 100644 --- a/docs/cli/cli.rst +++ b/docs/cli/cli.rst @@ -29,7 +29,7 @@ Overview - When to capture screenshots - ``failed`` - Useful in flaky UI tests to get screenshots on failure - * - ``--puls-no-html`` + * - ``--plus-no-html`` - Disable HTML report generation - False - Useful when integrating From 52e4438de5daac0b00bd91bf8efb4c2794692b95 Mon Sep 17 00:00:00 2001 From: laz Date: Tue, 8 Sep 2026 11:13:31 +0800 Subject: [PATCH 4/4] FIx puls-email force generate html --- docs/cli/cli.rst | 6 +++--- pytest_html_plus/plugin.py | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/cli/cli.rst b/docs/cli/cli.rst index 38e2724..099ed50 100644 --- a/docs/cli/cli.rst +++ b/docs/cli/cli.rst @@ -31,8 +31,8 @@ Overview - Useful in flaky UI tests to get screenshots on failure * - ``--plus-no-html`` - Disable HTML report generation - - False - - Useful when integrating + - ``False`` + - Useful when integrating. ``--plus-email`` will force HTML generation even if this flag is set * - ``--html-output`` - Directory for HTML output - ``report_output`` @@ -53,7 +53,7 @@ Overview - Path for XML report - ``None`` - Useful when generating multiple output types - * - ``--env`` or ``--environment`` or ``--rp-env` + * - ``--env`` or ``--environment`` or ``--rp-env`` - Include environment variables in the execution metadata. - Default: None - Useful for adding CI or custom environment metadata (safe values only). diff --git a/pytest_html_plus/plugin.py b/pytest_html_plus/plugin.py index 8226a91..f67e2c1 100644 --- a/pytest_html_plus/plugin.py +++ b/pytest_html_plus/plugin.py @@ -339,7 +339,11 @@ def pytest_sessionfinish(session, exitstatus): output_path=json_path, ) - if not session.config.getoption("--plus-no-html"): + should_generate_html = session.config.getoption( + "--plus-email" + ) or not session.config.getoption("--plus-no-html") + + if should_generate_html: script_path = os.path.join(os.path.dirname(__file__), "generate_html_report.py") if not os.path.exists(script_path): logger.warning( @@ -380,9 +384,7 @@ def pytest_sessionfinish(session, exitstatus): except Exception: logger.warning("Could not clean up screenshots directory") - if session.config.getoption("--plus-email") and not session.config.getoption( - "--plus-no-html" - ): + if session.config.getoption("--plus-email"): try: config = load_email_env() config["report_path"] = html_output @@ -391,7 +393,7 @@ def pytest_sessionfinish(session, exitstatus): except Exception as e: raise RuntimeError(f"Failed to send email: {e}") from e - if not session.config.getoption("--plus-no-html"): + if should_generate_html: # ---- Open report (controller only) ---- open_html_report( report_path=os.path.join(html_output, "report.html"),