Skip to main content

pytest plugin that allows selectively running tests several times and accepting *some* failures.

Project description

pytest-stochastics

A pytest plugin for running stochastic tests with configurable policies.

Definition: Stochastic Test - A test that may occasionally fail due to the non-deterministic character of the test subject. Evaluated by an at_least of out out_of model.

Features

  • Run stochastic tests multiple times with customizable pass/fail criteria
  • Configure different test plans with fallback options

Installation

You can install pytest-stochastics using pip:

pip install git+https://github.com/emcie-co/pytest-stochastics.git#egg=pytest_stochastics
# or
pip install git+ssh://git@github.com/emcie-co/pytest-stochastics.git#egg=pytest_stochastics

Or if you're using Poetry:

poetry add git+https://github.com/emcie-co/pytest-stochastics.git
# or
poetry add git+ssh://git@github.com/emcie-co/pytest-stochastics.git

Usage

Configuration

Create a pytest_stochastics_config.json file in your project root with your test configuration:

{
    "test_plans": [
        {
            "plan": "weak",
            "policy_tests": [
                {
                    "policy": "always",
                    "tests": [
                        "tests/test_abc/test_1", 
                    ]
                },
                {
                    "policy": "mostly",
                    "tests": [
                        "tests/test_abc/test_2",
                        "tests/test_abc/test_3"
                    ]
                }
            ]
        },
        {
            "plan": "strong",
            "policy_tests": [
                {
                    "policy": "always",
                    "tests": [
                        "tests/test_abc/test_2"
                    ]
                }
            ]
        }
    ],
    "policies": [
        {
            "policy": "always",
            "at_least": 3,
            "out_of": 3
        },
        {
            "policy": "mostly",
            "at_least": 2,
            "out_of": 3
        }
    ],
    "plan_fallbacks": [
        {
            "plan": "strong",
            "overrides": "weak"
        }
    ]
}

Running Tests

Run your tests as usual with pytest:

pytest

You may override the default behaviour by defining a custom plan named default.

To specify a plan:

pytest --plan="name of plan"

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_stochastics-0.2.4.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

pytest_stochastics-0.2.4-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_stochastics-0.2.4.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.9 Darwin/23.5.0

File hashes

Hashes for pytest_stochastics-0.2.4.tar.gz
Algorithm Hash digest
SHA256 412e2e8eb27d2b761970fc22a9a186846529a7358f46ad652da35bf1e1386d49
MD5 b5166cae381b5b4469b7933c42074e3b
BLAKE2b-256 00ea2978d0b94b7f08e4326d9d5c33d1eec760049e9df582eb1942d22a15fbe4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_stochastics-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6ff90135ec80d4b666d0cc611185c16ed60a491a48e0a811415821243899137b
MD5 518afc2d95caef08cdf0f23cdc965f4a
BLAKE2b-256 2fba127098cb4cf6f139393a41c1e343094e5ee5ab027ba2705e47e4cfe1b6f8

See more details on using hashes here.

Supported by

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