Skip to main content

pytest plugin for repeating tests

Project description

pytest-repeat is a plugin for pytest that makes it easy to repeat a single test, or multiple tests, a specific number of times.

license python version anaconda ci issues

Requirements

You will need the following prerequisites in order to use pytest-repeat:

  • Python 3.7+ or PyPy3

  • pytest 4 or newer

Installation

To install pytest-repeat:

$ pip install pytest-repeat

Repeating a test

Use the --count command line option to specify how many times you want your test, or tests, to be run:

$ pytest --count=10 test_file.py

Each test collected by pytest will be run count times.

If you want to mark a test in your code to be repeated a number of times, you can use the @pytest.mark.repeat(count) decorator:

import pytest


@pytest.mark.repeat(3)
def test_repeat_decorator():
    pass

If you want to override default tests executions order, you can use --repeat-scope command line option with one of the next values: session, module, class or function (default). It behaves like a scope of the pytest fixture.

function (default) scope repeats each test count or repeat times before executing next test. session scope repeats whole tests session, i.e. all collected tests executed once, then all such tests executed again and etc. class and module behaves similar session , but repeating set of tests is a tests from class or module, not all collected tests.

Repeating a test until failure

If you are trying to diagnose an intermittent failure, it can be useful to run the same test over and over again until it fails. You can use pytest’s -x option in conjunction with pytest-repeat to force the test runner to stop at the first failure. For example:

$ pytest --count=1000 -x test_file.py

This will attempt to run test_file.py 1000 times, but will stop as soon as a failure occurs.

UnitTest Style Tests

Unfortunately pytest-repeat is not able to work with unittest.TestCase test classes. These tests will simply always run once, regardless of --count, and show a warning.

Resources

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

Uploaded Source

Built Distribution

pytest_repeat-0.9.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file pytest_repeat-0.9.3.tar.gz.

File metadata

  • Download URL: pytest_repeat-0.9.3.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for pytest_repeat-0.9.3.tar.gz
Algorithm Hash digest
SHA256 ffd3836dfcd67bb270bec648b330e20be37d2966448c4148c4092d1e8aba8185
MD5 f530aa80bdafe1e75344a367e28800a2
BLAKE2b-256 865e99365eb229efff0b1bd475886150fc6db9937ab7e1bd21f6f65c1279e0eb

See more details on using hashes here.

File details

Details for the file pytest_repeat-0.9.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_repeat-0.9.3-py3-none-any.whl
Algorithm Hash digest
SHA256 26ab2df18226af9d5ce441c858f273121e92ff55f5bb311d25755b8d7abdd8ed
MD5 371710dee765b960000802dc40d0fc53
BLAKE2b-256 49a80a0aec0c2541b8baf4a0b95af2ba99abce217ee43534adf9cb7c908cf184

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