adamchainz / pytest-reverse

Pytest plugin to reverse test order.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pytest-reverse

image

image

image

pre-commit

Pytest plugin to reverse test order.


Testing a Django project? Check out my book Speed Up Your Django Tests which covers loads of recommendations to write faster, more accurate tests. I created pytest-reverse whilst working on the book!


Installation

Install with:

python -m pip install pytest-reverse

Python 3.8 to 3.12 supported.

Usage

Pytest will automatically find the plugin and use it when you run pytest. You can reverse test order by passing the --reverse flag:

pytest --reverse

You can make this always apply by adding it to the addopts setting in your pytest.ini (or other configuration file):

[pytest]
addopts = --reverse

History

I'm the creator and maintainer of pytest-randomly, a plugin for randomly ordering tests. @thbde opened an issue there pointing to the paper Empirically revisiting the test independence assumption, which covers test reordering techniques. It turns out that reversal is nearly as effective as randomization.

Test reversal is available in Django's test runner. I figured such an option or plugin would exist for pytest already, but it didn't, so I made it here.

About

Pytest plugin to reverse test order.

License:MIT License


Languages

Language:Python 100.0%