Skip to main content

pytest plugin to run tests in a specific order

Project description

pytest-order - a pytest plugin to order test execution

PyPI version Testsuite DocBuild codecov Python version PyPI - Downloads

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 all supported Python versions, with pytest versions >= 6.2.4 for Python < 3.14, and pytest >= 7.4 for Python 3.14. 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 linux -- Python 3.11.11, pytest-9.0.3, pluggy-1.6.0 -- 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.

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_order-1.5.0.tar.gz (54.1 kB view details)

Uploaded Source

Built Distribution

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

pytest_order-1.5.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_order-1.5.0.tar.gz
  • Upload date:
  • Size: 54.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pytest_order-1.5.0.tar.gz
Algorithm Hash digest
SHA256 96acd7587b5a2855dcaa4a898288103d202894a61afd813adbc9b77aab04d90d
MD5 3b5bc1d4c529a7654b5b743935a6ded4
BLAKE2b-256 97d882a5dc2aad3392f66c9741960fcbeeb45dd4d62eedb218aed6c52eea36eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_order-1.5.0.tar.gz:

Publisher: release-deploy.yml on pytest-dev/pytest-order

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_order-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_order-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pytest_order-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 667ba2b7303fe2c529848663e0a41dfb0cc4d64f09f87272e4a9a1751efb52b2
MD5 a6bdae2864442ce5b7e3b799382950bf
BLAKE2b-256 fd5cbd6a85b44beb8bd74c0e86ab699ef0e096e260dc90458b84fc54c28e4335

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_order-1.5.0-py3-none-any.whl:

Publisher: release-deploy.yml on pytest-dev/pytest-order

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