Skip to main content

pytest plugin for looping tests

Reason this release was yanked:

missing trylast mark caused pytest-loop to do nothing

Project description

pytest-loop is a plugin for pytest that makes it easy to loop a single test, or multiple tests, a specific number of times or for a certain duration of time. This plugin merges pytest-repeat and pytest-stress with a fix for test results.

License PyPI Python versions See Build Status on GitHub Actions Issues Requirements

Requirements

You will need the following prerequisites in order to use pytest-loop: - Python 3.7+ or PyPy - pytest 7 or newer

Installation

To install pytest-loop:

$ pip install pytest-loop

Usage

Iterative Loop:

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

$ pytest --loop=10 test_file.py

Each test collected by pytest will be run n times.

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

import pytest


@pytest.mark.loop(3)
def test_loop_decorator():
    pass

Time based loop:

Loop tests for 30 seconds:

$ pytest --seconds 30

Loop tests for 45 minutes:

$ pytest --minutes 45

Loop tests for 8 hours:

$ pytest --hours 8

Loop tests for 1 hour 8 minutes and 9 seconds:

$ pytest --hours 1 --minutes 8 --seconds 9

Need to wait some time after each test loop?:

$ pytest --delay 5 --hours 4 --minutes 30

You can also add these values to config files:

[pytest]
addopts = --hours 1 --minutes 30

Note: These loop times include setup and teardown operations as well. So if you have a test setup that takes 5 seconds, your actual tests will run for 5 seconds less than your desired time.

looping 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-loop to force the test runner to stop at the first failure. For example:

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

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

$ pytest --hours 10 -x test_file.

This will attempt to run test_file.py for 10 hours, but will stop as soon as a failure occurs.

UnitTest Style Tests

Unfortunately pytest-loop is not able to work with unittest.TestCase test classes. These tests will simply always run once, regardless of --loop, 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_loop-1.0.10.tar.gz (10.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_loop-1.0.10-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file pytest_loop-1.0.10.tar.gz.

File metadata

  • Download URL: pytest_loop-1.0.10.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for pytest_loop-1.0.10.tar.gz
Algorithm Hash digest
SHA256 bcfe490fea8c7ca123c7565e54ff2d8abcb1ac53f08776c980d7989d7221151e
MD5 37160a8c6e4e1bd86ca081cd43ee912b
BLAKE2b-256 c019faf4c9adfd12a4c281b8e7001cfd3f4e420fefcad100a5fefae6d64e8e9e

See more details on using hashes here.

File details

Details for the file pytest_loop-1.0.10-py3-none-any.whl.

File metadata

  • Download URL: pytest_loop-1.0.10-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for pytest_loop-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 1c12f8ef7fdff80c6eb4118058e8943d215f8aee1979e59851f7b520f4eb365c
MD5 0623634c35f6f4a6106098b34c80e7b1
BLAKE2b-256 5ec3cf847854d2545ed1b5a96f6464558036ea597c0a18696dd6d31af499effc

See more details on using hashes here.

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