Skip to main content

pytest-xdist-load-testing

PyPI version Python versions Build Status

A pytest-xdist scheduler for continuous load testing with weighted test selection

Features

  • Continuous Test Execution: Runs tests repeatedly until manually interrupted
  • Weighted Test Selection: Control test execution frequency using the @weight decorator
  • Random Selection: Tests are selected randomly based on their weights using random.choices
  • Graceful Interruption: Tests and fixtures can stop the scheduler programmatically
  • pytest-xdist Integration: Seamlessly integrates with pytest-xdist's distributed testing

Requirements

  • Python 3.9+
  • pytest >= 8.4.2
  • pytest-xdist >= 3.8.0

Installation

pip install pytest-xdist-load-testing

Examples

See the examples/ folder for working examples.

Basic Load Testing

Run your tests with pytest-xdist to enable the load testing scheduler:

pytest --load-test -n 4 path/to/test_module.py  # Run with 4 workers

The scheduler will continuously supply tests to workers until interrupted (Ctrl+C).

Important: Load testing requires specifying a single test module. Running multiple modules will result in an error:

pytest --load-test -n 4 tests/  # ERROR: Multiple modules detected
pytest --load-test -n 4 test_a.py test_b.py  # ERROR: Multiple modules

This restriction ensures proper fixture handling and test isolation during continuous execution.

Stopping the Scheduler

Tests can stop the scheduler programmatically using the stop_load_testing function:

from pytest_xdist_load_testing import stop_load_testing

def test_with_stop_condition():
    result = check_system_health()
    if result.critical_failure:
        stop_load_testing("Critical failure detected")

Load Test with Weighted Distribution

from pytest_xdist_load_testing import weight

@weight(70)
def test_read_heavy():
    """70% of requests"""
    assert api.get("/data").status_code == 200

@weight(20)
def test_write_operations():
    """20% of requests"""
    assert api.post("/data", json={}).status_code == 201

@weight(10)
def test_admin_operations():
    """10% of requests"""
    assert api.delete("/data/old").status_code == 204

Command Line Options

The plugin adds the following command line option:

--load-test    Enable load testing mode with continuous test execution

Rate Limiting and Shared State

For rate limiting and shared state management across pytest-xdist workers, see the companion package pytest-xdist-rate-limit.

Documentation

📚 Full Documentation

License

Distributed under the terms of the MIT license, "pytest-xdist-load-testing" is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.


This pytest plugin was generated with Cookiecutter along with @hackebrot's cookiecutter-pytest-plugin template.

Metadata

Release files for pytest-xdist-load-testing 0.2.4

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

Source distribution (sdist)

Source distribution for pytest-xdist-load-testing 0.2.4
File Size Uploaded
pytest_xdist_load_testing-0.2.4.tar.gz 23.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-xdist-load-testing 0.2.4
File Interpreter ABI Platform
pytest_xdist_load_testing-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 36.9 kB

Release files / pytest_xdist_load_testing-0.2.4.tar.gz

Download URL pytest_xdist_load_testing-0.2.4.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
80cc294d6c0de502f88cc911860e27adc2148ab771c1cc64056a7bae0cab7fe5
BLAKE2b-256 checksum
How to use checksums
f189296b269d4aaddef07dd5732f83f6bba9501d133a205af9c41ff606c49e53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 22, 2025.

Transparency log

Release files / pytest_xdist_load_testing-0.2.4-py3-none-any.whl

Download URL pytest_xdist_load_testing-0.2.4-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a40a2e7587f9c939465645b826815ba8b46b50795634bcae3f784c557751b32f
BLAKE2b-256 checksum
How to use checksums
858437d8c2248cec237c124066ba566103438d05fe3b1ab47395b132ff6abd3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 22, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

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