|
| 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. |
0 commit comments