M00N ReportPytest (Python)
Documentation/Reporters/Pytest

🐍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

Zero-Config Discovery

Registers via the standard pytest11 entry point - no conftest.py wiring.

CI Auto-Detection

Branch, commit, pipeline, and build metadata auto-populated on 7 CI providers.

Playwright Integration

page actions become pw:api steps; screenshots, video, and trace upload on failure.

Retry Tracking

Each pytest-rerunfailures attempt is recorded as a separate execution.

Resilience

Never fails the run; retries with backoff and a 5-failure circuit breaker.

Manual Steps & Attachments

step() context manager and attach() for files or bytes.

Case Linking

@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.

Store the API key outside version control. Read it from 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-pytest
For automatic Playwright page 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

pytest

Windows PowerShell

$env:M00N_SERVER_URL = "https://m00nreport.com"
$env:M00N_API_KEY = "m00n_xxxxxxxxxxxxx"
pytest
If either variable is missing, the reporter stays inactive and pytest behaves exactly as it would without it installed.

Configuration Reference

Every option can be set three ways. Precedence, highest wins: CLI flag > pytest.ini key > environment variable > default.

CLI flagini keyEnv varDefaultDescription
--m00n-server-urlm00n_server_urlM00N_SERVER_URLrequiredM00N Report server URL
--m00n-api-keym00n_api_keyM00N_API_KEYrequiredProject API key (m00n_...)
--m00n-launchm00n_launchM00N_LAUNCHRun <date>Title for this run
--m00n-tagsm00n_tagsM00N_TAGS[]Comma-separated tags
--m00n-attributesm00n_attributesM00N_ATTRIBUTES{}JSON object of custom run attributes
--m00n-debugm00n_debugM00N_DEBUGfalsePrints 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--falseForce-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
The reporter activates only once both 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, api

Or entirely from the CLI

pytest --m00n-server-url https://m00nreport.com --m00n-api-key m00n_xxxxxxxxxxxxx --m00n-tags smoke,api

CI/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 FieldAccepted Keys (case-insensitive)Example Value
Pipelinepipeline, GITHUB_WORKFLOW, CI_PIPELINE_NAME, JOB_NAMEDeploy Production
Branchbranch, git_branch, GITHUB_REF, CI_COMMIT_REF_NAME, BRANCH_NAMEmain
Commitcommit, git_commit, GITHUB_SHA, CI_COMMIT_SHA, GIT_COMMITa1b2c3d (truncated to 7 chars)
Build #build_number, GITHUB_RUN_NUMBER, CI_PIPELINE_ID, BUILD_NUMBER1234
Build URLbuild_url, GITHUB_SERVER_URL, CI_PIPELINE_URL, BUILD_URLhttps://github.com/... (clickable)
Environmentenvironment, env, DEPLOY_ENVstaging
Triggertrigger, GITHUB_EVENT_NAME, CI_PIPELINE_SOURCEpush
Tip: You can use any of the accepted key names. Only the first match per field is used.

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.

Caveat: because the controller does not collect tests under xdist (the workers do), the run's up-front total count is omitted for parallel runs; it fills in as tests report. Serial (non-xdist) runs still send total as before.

Known Limitations

Teardown-phase failures are not reported. If a test's own body passes but a fixture's teardown/finalizer raises afterward, that failure is not surfaced to M00N Report - the test keeps the status it already reported at 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.