How to detect and fix flaky tests in Pytest

This page summarizes the projects mentioned and recommended in the original post on dev.to

Judoscale - Save 47% on cloud hosting with autoscaling that just works
Judoscale integrates with Django, FastAPI, Celery, and RQ to make autoscaling easy and reliable. Save big, and say goodbye to request timeouts and backed-up task queues.
judoscale.com
featured
InfluxDB high-performance time series database
Collect, organize, and act on massive volumes of high-resolution data to power real-time intelligent systems.
influxdata.com
featured
  1. pytest-xdist

    pytest plugin for distributed testing and loop-on-failures testing modes.

    This is particularly problematic if you're using a library like pytest-xdist to distribute your tests across multiple CPUs. Testing in parallel and in random order introduces opportunities for both inconsistent system states to cause flakiness and race conditions where concurrently running tests interfere with each other.

  2. Judoscale

    Save 47% on cloud hosting with autoscaling that just works. Judoscale integrates with Django, FastAPI, Celery, and RQ to make autoscaling easy and reliable. Save big, and say goodbye to request timeouts and backed-up task queues.

    Judoscale logo
  3. pytest-rerunfailures

    a pytest plugin that re-runs failed tests up to -n times to eliminate flakey failures

    If you only have a few flaky tests, rerunning tests on failure to clear flakiness can be effective. Libraries like pytest-rerunfailures let you configure reruns easily, which reruns each test on the first failure to see if it's just flaky.

  4. pytest-flakefinder

    Runs tests multiple times to expose flakiness.

    Dropbox open-sourced a solution that helps you find flaky tests called pytest-flakefinder. This allows you to automatically rerun each test multiple times to find flaky tests. By default, the tool will run each test 50 times on the same commit and validate if the results are consistent. On the same commit, the code should be identical from run to run. If a test is not producing consistent results, it is considered flaky.

  5. pytest-replay

    Saves runs to allow to re-execute previous pytest runs to reproduce crashes or flaky tests

    After finding the high-impact tests to fix first, you can use a library like pytest-replay to help reproduce tests locally. The difficult-to-reproduce tests often reveal real problems with your infrastructure or code. Pytest-replay lets you replay failures from replay records saved in CI, which can be a real-time save.

  6. 0.30000000000000004

    Floating Point Math Examples

    This is due to the way floating point numbers are represented in memory, certain numbers like 0.3 are stored as a number very close to the original value (0.30000000000000004), but not the exact same. This problem also exists in other languages like JavaScript and C++, but is much more likely to cause problems in common applications of Python like machine learning and data science.

  7. InfluxDB

    InfluxDB high-performance time series database. Collect, organize, and act on massive volumes of high-resolution data to power real-time intelligent systems.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Run Python tests in parallel with Pytest

    1 project | news.ycombinator.com | 20 Dec 2023
  • PuDB: A console-based visual debugger for Python

    1 project | news.ycombinator.com | 29 Dec 2024
  • Playwright Alternative for API Testing

    2 projects | dev.to | 23 Dec 2024
  • Running Tests in a Kubernetes cluster

    1 project | /r/kubernetes | 13 Apr 2023
  • disallow-import-star: stop your users from using import *

    2 projects | /r/Python | 1 Apr 2023