Skip to content

Commit 2017cd0

Browse files
authored
v0.4.4 (#167)
* 163 initalization is delayed and time taken to launch tests reopen with git enabled (#166) * Get git information from cli and update docs * Update unit tests * Update actions * Updated checkout to v2 for reporterplus * Updated windows command * Updated marketplace docs * Updated version
1 parent 94465aa commit 2017cd0

11 files changed

Lines changed: 133 additions & 113 deletions

File tree

.github/workflows/actions-test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ jobs:
3535
poetry run playwright install --with-deps
3636
3737
- name: 🧪 Run playwright test and generate report using marketplace plugin
38-
uses: reporterplus/pytest-html-plus-action@v1
38+
uses: reporterplus/pytest-html-plus-action@v2
3939
with:
4040
htmloutput: "report_output_playwright"
4141
capturescreenshots: "all"
4242
testpath: "tests/browser/test_playwright.py"
4343
usepoetry: "true"
4444
xmlreport: "report_output_playwright/report.xml"
45+
gitbranch: "$(git rev-parse --abbrev-ref HEAD)"
4546

4647
- name: Upload reports
4748
if: always()

.github/workflows/unit-test-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
4444
- name: 🧪 Run tests with coverage
4545
run: |
46-
poetry run pytest --cov=pytest_html_plus tests/ --cov-fail-under=39 --cov-report=term --reruns 1 --ignore=tests/browser --generate-xml --xml-report report_output/final_xml_windows.xml
46+
poetry run pytest --cov=pytest_html_plus tests/ --cov-fail-under=39 --cov-report=term --reruns 1 --ignore=tests/browser --generate-xml --xml-report report_output/final_xml_windows.xml --git-branch $(git rev-parse --abbrev-ref HEAD)
4747
4848
- name: Upload HTML Report
4949
if: always()

.github/workflows/unit-test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ jobs:
3333
3434
- name: 🧪 Run tests with coverage
3535
run: |
36-
poetry run pytest --cov=pytest_html_plus tests/ --cov-fail-under=39 --cov-report=term --reruns 1 --ignore=tests/browser --generate-xml --xml-report report_output/final_xml_ubuntu.xml
36+
export REPORT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
37+
export REPORT_COMMIT="$(git rev-parse HEAD)"
38+
poetry run pytest --cov=pytest_html_plus tests/ --cov-fail-under=39 --cov-report=term --reruns 1 --ignore=tests/browser --generate-xml --xml-report report_output/final_xml_ubuntu.xml --git-branch "$REPORT_BRANCH" --git-commit "$REPORT_COMMIT"
3739
3840
- name: Upload HTML Report
3941
if: always()

docs/cli/cli.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ Overview
4141
- Path for XML report
4242
- ``None``
4343
- Useful when generating multiple output types
44+
* - ``--env``
45+
- Include environment variables in the execution metadata.
46+
- Default: None
47+
- Useful for adding CI or custom environment metadata (safe values only).
48+
* - ``--git-branch``
49+
- Branch name to display in the report.
50+
- Default: "NA"
51+
- Useful when running tests manually or when CI does not provide branch information.
52+
* - ``--git-commit``
53+
- Commit SHA to display in the report.
54+
- Default: "NA"
55+
- Useful for ensuring traceability when CI does not set commit environment variables.
56+
57+
4458

4559

4660
Detailed Option Usage

docs/cli/execution-metadata.rst

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
Version Control & Environment Metadata (``--git-branch``, ``--git-commit``, ``--env``)
2+
=======================================================================================
3+
4+
These flags allow you to inject version control and environment metadata directly into
5+
your test execution report. This is particularly useful for CI/CD integrations, manual test
6+
runs, or ensuring traceability when Git information is not automatically detectable.
7+
8+
Flags Overview
9+
--------------
10+
11+
- ``--git-branch``
12+
Specifies the Git branch name to display in the report.
13+
**Default:** ``NA``
14+
**Accepted Values:** Any string (e.g., ``main``, ``feature/login-ui``)
15+
Useful when running tests manually or in CI systems that do not automatically expose a branch name.
16+
17+
- ``--git-commit``
18+
Specifies the Git commit SHA to display in the report.
19+
**Default:** ``NA``
20+
**Accepted Values:** Any valid commit hash (e.g., ``5bb4c87e9da4ff1780540b25a04725ade5c3bc37``)
21+
Helps ensure full traceability of test runs, especially in detached HEAD mode.
22+
23+
- ``--env`` or ``--environment``
24+
Adds the value of a specific environment variable to the report metadata.
25+
**Default:** ``None``
26+
**Accepted Values:** A single environment variable key (e.g., ``BUILD_ID``) or any text of your choice for (e.g. your env name like staging)
27+
Useful for adding CI job IDs, build numbers, or other contextual metadata.
28+
29+
Usage Examples
30+
--------------
31+
32+
**Specify branch and commit explicitly:**
33+
34+
.. code-block:: bash
35+
36+
pytest --git-branch main --git-commit 5bb4c87
37+
38+
**Include a CI environment variable in the metadata:**
39+
40+
.. code-block:: bash
41+
42+
pytest --env BUILD_ID
43+
44+
If ``BUILD_ID`` is set in your environment, the report will include:
45+
46+
47+
**Combine all three flags for complete control:**
48+
49+
.. code-block:: bash
50+
51+
export REPORT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
52+
export REPORT_COMMIT="$(git rev-parse HEAD)"
53+
54+
pytest --git-branch "$REPORT_BRANCH" --git-commit "$REPORT_COMMIT"
55+
--env CI_JOB_ID
56+
57+
Use Cases
58+
---------
59+
60+
- **CI/CD Pipelines**
61+
Pass branch, commit, or pipeline identifiers directly into your reports for accurate mapping
62+
of test runs to code snapshots.
63+
64+
- **Manual Test Execution**
65+
Useful when running tests outside a Git repository, inside a Docker container, or from
66+
distributed artifacts where Git metadata may be unavailable.
67+
68+
- **Build & Release Tracking**
69+
Supply values like ``BUILD_ID``, ``RUN_NUMBER``, or ``PIPELINE_ID`` so downstream systems
70+
can correlate test results with deployments.
71+
72+
Report Contents
73+
---------------
74+
75+
- When supplied, branch and commit information will be added to the report header.
76+
- The value of the environment variable provided through ``--env`` will appear as a key/value
77+
entry under execution metadata.
78+
- If the given environment variable does not exist, its value will be shown as ``NA``.
79+
80+
Important Notes
81+
---------------
82+
83+
- If not provided, both ``--git-branch`` and ``--git-commit`` default to ``NA``.
84+
- The ``--env`` flag accepts **only one environment variable key per usage**.
85+
If you need to include multiple variables, specify the flag multiple times.
86+
- Avoid using ``--env`` to expose sensitive information such as API tokens or passwords.

docs/marketplace/usage.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ pytest-html-plus plugin options.
9999
* - ``usepoetry``
100100
- Run pytest through ``poetry run pytest``.
101101
- ``false``
102+
* - ``gitbranch``
103+
- Insert value of the branch from the CI
104+
- ``NA``
105+
* - ``gitcommit``
106+
- Insert value of the branch from the CI
107+
- ``NA``
102108

103109

104110
Examples

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pytest-html-plus"
3-
version = "0.4.3"
3+
version = "0.4.4"
44
description = "Get started with rich pytest reports in under 3 seconds. Just install the plugin — no setup required. The simplest, fastest reporter for pytest."
55
readme = "README.md"
66
authors = ["reporterplus"]

pytest_html_plus/compute_git_branch.py

Lines changed: 0 additions & 99 deletions
This file was deleted.

pytest_html_plus/compute_report_metadata.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import json
22
from datetime import datetime
33

4-
from pytest_html_plus.utils import is_main_worker, get_env_marker, get_git_information, get_report_title, \
4+
from pytest_html_plus.utils import is_main_worker, get_env_marker, get_report_title, \
55
get_python_version
66

77

8-
def write_plus_metadata_if_main_worker(config, report_path, output_path="plus_metadata.json"):
8+
def write_plus_metadata_if_main_worker(config, report_path, output_path="plus_metadata.json", **kwargs):
99
if not is_main_worker():
1010
return
11-
branch, commit = get_git_information()
11+
branch = kwargs.get("git_branch", "NA")
12+
commit = kwargs.get("git_commit", "NA")
1213
metadata = {
1314
"report_title": get_report_title(output_path=report_path),
1415
"environment": get_env_marker(config),

pytest_html_plus/plugin.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,14 @@ def pytest_sessionfinish(session, exitstatus):
162162

163163
def pytest_sessionstart(session):
164164
html_output = session.config.getoption("--html-output") or "report_output"
165+
git_branch = session.config.getoption("--git-branch") or "NA"
166+
git_commit = session.config.getoption("--git-commit") or "NA"
165167
configure_logging()
166168
session.config.addinivalue_line(
167169
"markers", "link(url): Add a link to external test case or documentation."
168170
)
169-
write_plus_metadata_if_main_worker(session.config, report_path=html_output)
171+
write_plus_metadata_if_main_worker(session.config, report_path=html_output,
172+
git_branch=git_branch, git_commit=git_commit)
170173

171174

172175
def pytest_load_initial_conftests(args):
@@ -221,6 +224,18 @@ def pytest_addoption(parser):
221224
default=None,
222225
help="Path to output the XML report (used with --generatexml)"
223226
)
227+
parser.addoption(
228+
"--git-branch",
229+
action="store",
230+
default="NA",
231+
help="Helps show branch information on the report"
232+
)
233+
parser.addoption(
234+
"--git-commit",
235+
action="store",
236+
default="NA",
237+
help="Helps show commitId information on the report"
238+
)
224239

225240
import logging
226241
import sys

0 commit comments

Comments
 (0)