pytest-random-order

1.2.0 · active · verified Fri Apr 10

pytest-random-order is a pytest plugin that randomises the order of tests. This can be useful to detect a test that passes just because it happens to run after an unrelated test that leaves the system in a favourable state. The plugin allows users to control the level of randomness they want to introduce and to disable reordering on subsets of tests. Tests can be rerun in a specific order by passing a seed value reported in a previous test run. Current version is 1.2.0.

Warnings

Install

Imports

Quickstart

Install the plugin, then run pytest with the `--random-order` command-line flag. For persistent randomization, configure `addopts` in your `pytest.ini` or `pyproject.toml` file. This example demonstrates basic test functions which will be randomized when the plugin is active.

# test_example.py
def test_alpha():
    assert True

def test_beta():
    assert True

def test_gamma():
    assert True

# Run from your terminal:
# pip install pytest pytest-random-order
# pytest --random-order
#
# To always enable it, add to pytest.ini (or pyproject.toml):
# [pytest]
# addopts = --random-order

view raw JSON →