🐍Pytest Reporter
A pytest reporter for M00N Report. Installs as a zero-config pytest11 plugin, auto-detects CI metadata on 7 providers, and - when the real Playwright package is present - auto-records page actions as steps and uploads screenshots, videos, and traces for failed tests. Verified against the reporter-conformance suite, including a fault-injection baseline.
Features
Registers via the standard pytest11 entry point - no conftest.py wiring.
Branch, commit, pipeline, and build metadata auto-populated on 7 CI providers.
page actions become pw:api steps; screenshots, video, and trace upload on failure.
Each pytest-rerunfailures attempt is recorded as a separate execution.
Never fails the run; retries with backoff and a 5-failure circuit breaker.
step() context manager and attach() for files or bytes.
@pytest.mark.m00n(case_id=...) links a test to an existing case.
AI Setup Prompt
A complete, self-contained prompt for integrating this reporter into an existing pytest project using an AI assistant. The prompt covers installation, the environment-variable and pytest.ini configuration forms, manual steps and attachments, case linking, retries, a verification checklist, and the most common integration pitfalls.
M00N_API_KEY and supply it as a CI secret; never hard-code it in pytest.ini.Quick Start
Install the package and set two environment variables. Pytest discovers the plugin automatically once it is installed - there is no -p flag or conftest.py block to add.
pip install m00nreport-pytestpage step recording, screenshots, and artifact uploads, install the optional extra instead: pip install m00nreport-pytest[playwright]. It pulls in pytest-playwright; browser binaries still need a separate python -m playwright install chromium.bash / zsh
export M00N_SERVER_URL=https://m00nreport.com # or your self-hosted URL
export M00N_API_KEY=m00n_xxxxxxxxxxxxx # your project API key
pytestWindows PowerShell
$env:M00N_SERVER_URL = "https://m00nreport.com"
$env:M00N_API_KEY = "m00n_xxxxxxxxxxxxx"
pytestConfiguration Reference
Every option can be set three ways. Precedence, highest wins: CLI flag > pytest.ini key > environment variable > default.
| CLI flag | ini key | Env var | Default | Description |
|---|---|---|---|---|
--m00n-server-url | m00n_server_url | M00N_SERVER_URL | required | M00N Report server URL |
--m00n-api-key | m00n_api_key | M00N_API_KEY | required | Project API key (m00n_...) |
--m00n-launch | m00n_launch | M00N_LAUNCH | Run <date> | Title for this run |
--m00n-tags | m00n_tags | M00N_TAGS | [] | Comma-separated tags |
--m00n-attributes | m00n_attributes | M00N_ATTRIBUTES | {} | JSON object of custom run attributes |
--m00n-debug | m00n_debug | M00N_DEBUG | false | Prints a [m00nreport] line to stdout for every HTTP retry attempt and any final exhaustion, plus the attach()-outside-an-active-test edge case; silent when off |
--m00n-disable | - | - | false | Force-disable the reporter for this invocation, even if a server url and api key are set. CLI-only - no ini or env equivalent by design |
server_url and api_key resolve to a value. If exactly one is set, pytest prints a single [m00nreport] serverUrl and apiKey are required. Reporter disabled. warning to stderr (usually a typo in an env var name) and continues; if neither is set, the reporter is silently inactive. A malformed M00N_ATTRIBUTES JSON string is ignored (falls back to {}) rather than crashing the run.pytest.ini example
[pytest]
m00n_server_url = https://m00nreport.com
m00n_api_key = m00n_xxxxxxxxxxxxx
m00n_launch = Nightly Regression
m00n_tags = smoke, apiOr entirely from the CLI
pytest --m00n-server-url https://m00nreport.com --m00n-api-key m00n_xxxxxxxxxxxxx --m00n-tags smoke,apiCI/CD Context Banner
When a run carries CI/CD-related attribute keys - whether auto-detected (see Concepts → CI Auto-Detection below) or passed via --m00n-attributes - M00N Report automatically displays them in a dedicated CI context banner at the top of the launch view. Attributes that don't match the keys below are shown as regular attribute badges instead, which is where triggered_by and ci_job_url currently land.
Recognized CI Attribute Keys
| Banner Field | Accepted Keys (case-insensitive) | Example Value |
|---|---|---|
| Pipeline | pipeline, GITHUB_WORKFLOW, CI_PIPELINE_NAME, JOB_NAME | Deploy Production |
| Branch | branch, git_branch, GITHUB_REF, CI_COMMIT_REF_NAME, BRANCH_NAME | main |
| Commit | commit, git_commit, GITHUB_SHA, CI_COMMIT_SHA, GIT_COMMIT | a1b2c3d (truncated to 7 chars) |
| Build # | build_number, GITHUB_RUN_NUMBER, CI_PIPELINE_ID, BUILD_NUMBER | 1234 |
| Build URL | build_url, GITHUB_SERVER_URL, CI_PIPELINE_URL, BUILD_URL | https://github.com/... (clickable) |
| Environment | environment, env, DEPLOY_ENV | staging |
| Trigger | trigger, GITHUB_EVENT_NAME, CI_PIPELINE_SOURCE | push |
Parallel execution (pytest-xdist)
Parallel runs with pytest-xdist (-n auto, -n 4, distributed workers) are supported and report as a single launch - no extra wiring. Using the same master/worker model as Allure and ReportPortal, the controller process starts the run once and shares its run id with every worker before the worker boots, each worker reports its slice of tests against that shared run, and the controller closes the run once at the end. The final status is aggregated across workers, so a failure on any worker fails the whole run. Retries (retry 0, 1, ... survive across workers), skips, steps, and attachments from every worker merge into the one launch, identical to a serial run - just faster.
total count is omitted for parallel runs; it fills in as tests report. Serial (non-xdist) runs still send total as before.Known Limitations
call time. This is a known limitation of this release, not a bug in your fixtures.Conformance
This reporter targets the M00N Report ingest v2 contract (public OpenAPI document) and is verified against the M00N Report reporter-conformance suite: both the normal and fault-injection (injected transient 5xx) baselines pass, all 11 protocol invariants green on the normal run and all 12 (the additional RETRIES_ON_FAILURE check) green on the fault-injection run.
Unlike the JS Playwright reporter (1.0.10), whose test/start call is fire-and-forget with no retry, this reporter's fire-and-forget calls run through a retrying background worker and test/complete waits for its matching test/start to land before sending, so the fault-injection baseline stays fully green instead of losing test/start records to a single transient 5xx.
Concepts
Reference documentation for each subsystem of the reporter: Playwright integration, manual steps and attachments, case linking and retries, CI auto-detection, resilience, and troubleshooting.