Skip to main content

xdist scheduler to repeately run tests

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_xdist_load_testing-0.2.4.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_xdist_load_testing-0.2.4-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file pytest_xdist_load_testing-0.2.4.tar.gz.

File metadata

File hashes

Hashes for pytest_xdist_load_testing-0.2.4.tar.gz
Algorithm Hash digest
SHA256 80cc294d6c0de502f88cc911860e27adc2148ab771c1cc64056a7bae0cab7fe5
MD5 15fb830319cd5a7e3b895dc42311de4e
BLAKE2b-256 f189296b269d4aaddef07dd5732f83f6bba9501d133a205af9c41ff606c49e53

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_xdist_load_testing-0.2.4.tar.gz:

Publisher: release.yml on xverges/pytest-xdist-load-testing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_xdist_load_testing-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_xdist_load_testing-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a40a2e7587f9c939465645b826815ba8b46b50795634bcae3f784c557751b32f
MD5 1d60b96b638570c6c2a931111ce637da
BLAKE2b-256 858437d8c2248cec237c124066ba566103438d05fe3b1ab47395b132ff6abd3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_xdist_load_testing-0.2.4-py3-none-any.whl:

Publisher: release.yml on xverges/pytest-xdist-load-testing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page