Skip to main content

pytest plugin to run your tests in a specific order

Project description

pytest-order - a pytest plugin to order test execution

PyPI version Testsuite DocBuild codecov Python version

pytest-order is a pytest plugin that allows you to customize the order in which your tests are run. It uses the marker order that defines when a specific test shall run, either by using an ordinal number, or by specifying the relationship to other tests.

pytest-order is a fork of pytest-ordering that provides additional features like ordering relative to other tests.

pytest-order works with Python 3.7 - 3.12, with pytest versions >= 5.0.0 for all versions up to Python 3.9, and for pytest >= 6.2.4 for Python >= 3.10. pytest-order runs on Linux, macOS and Windows.

Documentation

Apart from this overview, the following information is available:

Features

pytest-order provides the following features:

  • ordering of tests by index
  • ordering of tests both from the start and from the end (via negative index)
  • ordering of tests relative to each other (via the before and after marker attributes)
  • session-, module- and class-scope ordering via the order-scope option
  • directory scope ordering via the order-scope-level option
  • hierarchical module and class-level ordering via the order-group-scope option
  • ordering tests with pytest-dependency markers if using the order-dependencies option, more information about pytest-dependency compatibility here
  • sparse ordering of tests via the sparse-ordering option
  • usage of custom markers for ordering using the order-marker-prefix option

Overview

(adapted from the original project)

Have you ever wanted to easily run one of your tests before any others run? Or run some tests last? Or run this one test before that other test? Or make sure that this group of tests runs after this other group of tests?

Now you can.

Install with:

pip install pytest-order

This defines the order marker that you can use in your code with different attributes.

For example, this code:

import pytest

@pytest.mark.order(2)
def test_foo():
    assert True

@pytest.mark.order(1)
def test_bar():
    assert True

yields the output:

$ pytest test_foo.py -vv
============================= test session starts ==============================
platform darwin -- Python 3.7.1, pytest-5.4.3, py-1.8.1, pluggy-0.13.1 -- env/bin/python
plugins: order
collected 2 items

test_foo.py:7: test_bar PASSED
test_foo.py:3: test_foo PASSED

=========================== 2 passed in 0.01 seconds ===========================

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license, pytest-order is free and open source software.

History

This is a fork of pytest-ordering. That project is not maintained anymore, and there are several helpful PRs that are now integrated into pytest-order. The idea and most of the initial code has been created by Frank Tobia, the author of that plugin, and contributors.

While derived from pytest_ordering, pytest-order is not compatible with pytest-ordering due to the changed marker name (order instead of run). Additional markers defined in pytest_ordering are all integrated into the order marker (for a rationale see also this issue).

Ordering relative to other tests and all the configuration options are not available in the released version of pytest-ordering. However, most of these features are derived from or inspired by issues and pull requests already existing in pytest-ordering.

Download files

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

Source Distribution

pytest_order-1.3.0.tar.gz (47.5 kB view details)

Uploaded Source

Built Distribution

pytest_order-1.3.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file pytest_order-1.3.0.tar.gz.

File metadata

  • Download URL: pytest_order-1.3.0.tar.gz
  • Upload date:
  • Size: 47.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for pytest_order-1.3.0.tar.gz
Algorithm Hash digest
SHA256 51608fec3d3ee9c0adaea94daa124a5c4c1d2bb99b00269f098f414307f23dde
MD5 f929658fd82b61ff37fb4e43221b0e68
BLAKE2b-256 1d6602ae17461b14a52ce5a29ae2900156b9110d1de34721ccc16ccd79419876

See more details on using hashes here.

File details

Details for the file pytest_order-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_order-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for pytest_order-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2cd562a21380345dd8d5774aa5fd38b7849b6ee7397ca5f6999bbe6e89f07f6e
MD5 7fb73d8000fbc20535ab90823e230b24
BLAKE2b-256 1b7359b038d1aafca89f8e9936eaa8ffa6bb6138d00459d13a32ce070be4f280

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