Skip to main content

pytest-mergify

Find the pytest tests that pass and fail on the same code, and quarantine them so they stop failing your CI. Requires a Mergify account (set MERGIFY_TOKEN in CI); free for open source. Why tests go flaky in pytest, and how to fix them: mergify.com/learn/flaky-tests/pytest.

Pytest plugin for Mergify Test Engine.

More information at https://mergify.com

Features

  • Test tracing — Sends OpenTelemetry traces for every test to Mergify's API
  • Flaky test detection — Intelligently reruns tests to detect flakiness with budget constraints
  • Test quarantine — Quarantines failing tests so they don't block CI
  • Test selection — Runs first the tests a merge-queue bisection step failed in the step above, and stops as soon as one fails again

Installation

Install the package alongside pytest (>= 7.0):

pip install pytest-mergify

The plugin is auto-discovered by pytest — no manual registration required.

Configuration

Set the MERGIFY_TOKEN environment variable with your Mergify API token.

The plugin activates automatically when running in CI (detected via the CI environment variable). To enable outside CI, set MERGIFY_CI_ENABLE=true.

Environment Variables

Variable Description Default
MERGIFY_TOKEN Mergify API authentication token (required)
MERGIFY_API_URL Mergify API endpoint https://api.mergify.com
MERGIFY_CI_ENABLE Force-enable outside CI false
MERGIFY_CI_DEBUG Print spans to console instead of uploading false
MERGIFY_TRACEPARENT W3C distributed trace context —
MERGIFY_TEST_JOB_NAME Mergify test job name —
MERGIFY_FAIL_FIRST_ENABLE Set to false to never run first what a merge-queue bisection step of this job failed before true
MERGIFY_TEST_RETRY_ENABLE Set to false to have this job retry no failing test, whatever the repository sets true

The names these replace, PYTEST_MERGIFY_ENABLE and PYTEST_MERGIFY_DEBUG, are deprecated: they still work when the new name is not set, and the plugin says which one to switch to at the end of the session.

For detailed documentation, see the official guide.

Bisection steps: failures first

When Mergify's merge queue splits a failed batch, each bisection step only needs to tell whether it is red. The plugin asks Mergify whether the current run is such a step and, if so, runs first the tests this job failed in the run the step was split from (Fail First). They run before every other test; if one of them fails again, the step is red whatever the rest does, so the run stops there (exit code 1, the remaining tests not run) and the queue can split again without waiting for the suite. If they all pass, the rest of the suite runs as usual. No test is ever skipped, so a green step still comes from a full suite. A test a retry rescued, or a quarantined failure, does not stop the run.

It is on by default: there is nothing to configure, the plugin uses the token and job identity it already has, and Mergify decides. A job that must always run its suite in its usual order turns it off:

      - name: Run tests
        run: pytest
        env:
          MERGIFY_TOKEN: ${{ secrets.MERGIFY_TOKEN }}
          MERGIFY_FAIL_FIRST_ENABLE: "false"

Such a job never queries the endpoint; everything else the plugin does — test tracing, flaky detection, quarantine — is unaffected either way. Only a recognised no (false, no, off, 0) turns it off. MERGIFY_TEST_SELECTION_ENABLE, its former name, is still read while the new one is unset or empty, and the summary at the end of the run says to switch.

It only ever asks in a build of a merge-queue batch, the only builds a bisection step can be: on GitHub Actions, the event of the draft pull request the queue opened; on any other build, the queue's git note on the branch, one git ls-remote against origin that runs while the tests are being collected. Every other build asks nothing and sends nothing. Of a batch's builds, only those below a failed batch, and not retrying their own checks, ask: the others cannot be a bisection step, and send their results only when the batch holds two pull requests or more, so a bisection step may read them, or when they failed. A build where git cannot answer (no origin, credentials the test step does not hold) asks, as it would without this.

Every other situation — a run that is not a bisection step, an unreachable API, an answer from a newer Mergify this plugin does not understand — runs the full suite in its usual order. It is also enabled per organization on Mergify's side: until yours has it, every run is served the full suite, says nothing about it, and still sends its results, which show what Fail First would do there.

Under pytest-xdist this works with the load (the default with -n) and worksteal schedulers; with loadgroup, tests marked xdist_group still run before them. With loadscope and loadfile, xdist schedules whole modules or classes by size, so those tests do not run first: the run still stops once they have all run and one failed again. Workers on a remote gateway (--tx ssh=…) run to the end.

An opted-in job also tells Mergify what it concluded when its session ends — which tests failed, how many ran — in one small request sent before the test results are uploaded. That is what the next bisection step of the job is answered from, seconds after this one finished, without waiting for the results to be processed. If that request fails, the run's own result is untouched: the terminal says so, and the next step simply runs its full suite in its usual order.

Development

Prerequisites

  • Python >= 3.10
  • uv

Setup

uv sync

Running Tests

uv run poe test

uv run poe build builds the wheel into dist/; when one is there, poe test runs against it rather than the project's own install, which is how CI builds the extension once for every Python version. Every uv-driven build of the extension uses Cargo's dev profile.

Linting

uv run poe lint

License

Proprietary. Use is governed by the Mergify Terms of Service.

Metadata

Release files for pytest-mergify 2026.11.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pytest-mergify 2026.11.3
File Actions
pytest_mergify-2026.11.3-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for pytest_mergify-2026.11.3-cp310-abi3-win_amd64.whl
pytest_mergify-2026.11.3-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for pytest_mergify-2026.11.3-cp310-abi3-musllinux_1_2_x86_64.whl
pytest_mergify-2026.11.3-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for pytest_mergify-2026.11.3-cp310-abi3-musllinux_1_2_aarch64.whl
pytest_mergify-2026.11.3-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details for pytest_mergify-2026.11.3-cp310-abi3-manylinux_2_28_x86_64.whl
pytest_mergify-2026.11.3-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details for pytest_mergify-2026.11.3-cp310-abi3-manylinux_2_28_aarch64.whl
pytest_mergify-2026.11.3-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for pytest_mergify-2026.11.3-cp310-abi3-macosx_11_0_arm64.whl
pytest_mergify-2026.11.3-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for pytest_mergify-2026.11.3-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 28.4 MB

Release files / pytest_mergify-2026.11.3-cp310-abi3-win_amd64.whl

Download URL pytest_mergify-2026.11.3-cp310-abi3-win_amd64.whl
Size 3.9 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
bab21962c0e92f9309431ab98bffde1c7fa2b9edbabed6a6f9992603f114b464
BLAKE2b-256 checksum
How to use checksums
9db50ff358f603afe906503f0b280922dab6c9b0ad9c2f12e16b9626f76c1361
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / pytest_mergify-2026.11.3-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL pytest_mergify-2026.11.3-cp310-abi3-musllinux_1_2_x86_64.whl
Size 4.3 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
136be614ec20d063e4dc662de15b43b8db730daaf4fa87442bb8465b44aa08ca
BLAKE2b-256 checksum
How to use checksums
296fd266b16fa0ef6c97e85c3bf72be9a40cf08953bd2f06f795be75a1a27760
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / pytest_mergify-2026.11.3-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL pytest_mergify-2026.11.3-cp310-abi3-musllinux_1_2_aarch64.whl
Size 4.0 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
a1bc796bee1251f93dbee994093df77292a36d28efa90bcc17285dbc7d0b2acd
BLAKE2b-256 checksum
How to use checksums
103c711a8a900f45fb615e95f72ed8d185ebd8d6d0ff85653a9a610b03d8f02f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / pytest_mergify-2026.11.3-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL pytest_mergify-2026.11.3-cp310-abi3-manylinux_2_28_x86_64.whl
Size 4.3 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
8e988d69d1c4883eff97f8691adab60621edf94b3d2e63fd014e339563d48322
BLAKE2b-256 checksum
How to use checksums
86167449baf249badc7364ab60b1f4de78215d1306391b2fbcdd6d1e095030f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / pytest_mergify-2026.11.3-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL pytest_mergify-2026.11.3-cp310-abi3-manylinux_2_28_aarch64.whl
Size 4.0 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
0038a34de329ae13bfe7392836738e580e5a4455dfcca6a8dd8bcf94a8cd2966
BLAKE2b-256 checksum
How to use checksums
88b7b387d9dba538a298365744cf2bb30c3227f8c6be894b36f2d8af1339370c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / pytest_mergify-2026.11.3-cp310-abi3-macosx_11_0_arm64.whl

Download URL pytest_mergify-2026.11.3-cp310-abi3-macosx_11_0_arm64.whl
Size 3.8 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
4421cef38e1d035d14e3e120145e05d2f6e842b48316a759942dffa19ce483d1
BLAKE2b-256 checksum
How to use checksums
6f0a5257527c68f4fab6e34314e5300ceb2b28bd321cbcf0e000b85acf9e9711
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / pytest_mergify-2026.11.3-cp310-abi3-macosx_10_12_x86_64.whl

Download URL pytest_mergify-2026.11.3-cp310-abi3-macosx_10_12_x86_64.whl
Size 4.1 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
08f970750cebd3a826fe0e1c3af67bf5a9f64709ce43f28e01af70d2917ad037
BLAKE2b-256 checksum
How to use checksums
d750ee8d80869a0e5e2ef5f5a0bcd4b3be613c2e6661cf88c0891d2285e78cbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Security for pytest-mergify 2026.11.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 7 files in this release have been uploaded with provenance metadata.

Select from 7 files

Attestation for pytest_mergify-2026.11.3-cp310-abi3-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page