skillfed

pytest-retry

Adds the ability to retry flaky tests in CI environments

pytest-retry v1.7.0 2.6M downloads/30d#2,982 on PyPI41
Permissive license MIT License Copyright (c) 2022 Silas Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the… (full text in the JSON record) DORMANT released

What it is and what it does

pytest-retry extends pytest with the ability to automatically re-run tests that fail, addressing the problem of flaky tests that pass inconsistently due to timing issues, external service delays, or environment race conditions. It works as a pytest plugin with two main modes: global retry settings applied to all tests via command-line flags (--retries, --retry-delay) or configuration files, and per-test control via the @pytest.mark.flaky decorator for fine-grained retry policies.

The plugin integrates into pytest's reporting flow to track and display retried tests separately. It supports exception filtering (retry only on specific exceptions or exclude certain ones), configurable timing methods (overwrite vs. cumulative), and custom outcome labels for compatibility with other reporting tools. Teardown steps run after each failed attempt to ensure clean state before retries, though fixture setup itself is not retried. The package is designed as a pragmatic short-term solution while permanent fixes are implemented, not a substitute for addressing root causes of flakiness.

Use it for:

  • Retry all tests in a CI pipeline up to N times to reduce false negatives from transient environment issues.
  • Mark specific tests known to be flaky with @pytest.mark.flaky to retry only those without affecting the full suite.
  • Retry tests only when they fail with specific exceptions (e.g., network timeouts) while failing immediately on assertion errors.
  • Add delays between retry attempts to allow intermittent services or resources to recover.
  • Generate detailed reports of which tests were retried and why, to identify candidates for permanent fixes.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

pytest-retry is a pytest plugin that automatically retries failed tests, with configurable retry counts, delays, and exception filtering to help manage flaky tests in CI environments.

Yes, if you have flaky tests in CI and need a quick way to reduce false failures while you investigate root causes. The low install friction, permissive license, and absence of known vulnerabilities make it safe to add. Maintenance is dormant but recent, and the plugin's scope is narrow enough that stability is likely. Not recommended as a permanent solution—use it to buy time while fixing the underlying test or environment issues.

Install

pytest-retry on PyPI

pip

pip install pytest-retry

uv

uv add pytest-retry

poetry

poetry add pytest-retry

Installing pytest-retry

Before you install

Low friction install with a single runtime dependency on pytest. Maintenance is dormant but the package has received updates as recently as 2025-01-19, and no known vulnerabilities are recorded.

License in practice

MIT License permits use, modification, and distribution with minimal restrictions, making it safe for both open-source and commercial projects.

Quickstart

pip install pytest-retry

# In conftest.py or test file:
import pytest

@pytest.mark.flaky(retries=2, delay=1)
def test_unreliable_service():
    pass

# Or run globally:
# pytest --retries 2 --retry-delay 1

Requires Python 3.9+ and pytest 7.0.0+.

Verify before relying

  • Whether the plugin's dormant maintenance status indicates sufficient ongoing support for production use.
  • Performance impact of re-running class and module fixtures on large test suites.
  • Compatibility with pytest plugins beyond pytest-html when using custom retry-outcome values.

Package facts

License MIT License Copyright (c) 2022 Silas Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the… (full text in the JSON record) (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies 1 — pytest
Maintenance dormant — 572 days since the last release
Last repo commit
First released
Downloads 2,588,607/month — #2,982 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pytest_retry-1.7.0-py3-none-any.whl

Keywords: rerun, pytest, flaky

Framework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.9

Tags

pytest flaky test retrytest rerun on failurepytest retry pluginflaky test handlingretry failed tests pytesttest resilience ciintermittent test failures
pytest-pluginci-resilienceflaky-tests

More Testing packages

pluggy

Pluggy provides a plugin system that lets you…

permissive · top 100 on PyPI

pytest

pytest is a testing framework that lets you…

permissive · top 100 on PyPI

virtualenv

virtualenv creates isolated Python environments…

permissive · top 100 on PyPI

coverage

Coverage.py measures which lines of Python code…

permissive · top 1,000 on PyPI

pytest-asyncio

pytest-asyncio is a pytest plugin that enables…

permissive · top 1,000 on PyPI

pytest-json-ctrf

A pytest plugin that generates test reports in…

permissive · top 1,000 on PyPI

pytest-mergify

A pytest plugin that integrates with Mergify to…

permissive · top 15,000 on PyPI

pytest-rerunfailures

A pytest plugin that automatically reruns…

copyleft · top 1,000 on PyPI

flaky

A pytest plugin that automatically reruns…

permissive · top 5,000 on PyPI

pytest-fail-slow

A pytest plugin that marks tests as failed if…

permissive · top 15,000 on PyPI

robotframework-retryfailed

A Robot Framework listener that automatically…

permissive · top 15,000 on PyPI

pytest-cache

A pytest plugin that persists test state across…

permissive · top 15,000 on PyPI

pytest-loop

A pytest plugin that repeats tests a fixed…

copyleft · top 15,000 on PyPI

pytest-repeat

A pytest plugin that repeats test execution a…

copyleft · top 5,000 on PyPI

pytest-sentry

A pytest plugin that sends test failure and…

permissive · top 15,000 on PyPI

pytest-github-actions-annotate-failures

A pytest plugin that automatically annotates…

permissive · top 5,000 on PyPI