Skip to main content

Race conditions tester for pytest

Project description

https://github.com/idlesign/pytest-race

https://img.shields.io/pypi/v/pytest-race.svg https://img.shields.io/pypi/dm/pytest-race.svg https://img.shields.io/pypi/l/pytest-race.svg https://img.shields.io/coveralls/idlesign/pytest-race/master.svg https://img.shields.io/travis/idlesign/pytest-race/master.svg https://landscape.io/github/idlesign/pytest-race/master/landscape.svg?style=flat

Description

Race conditions tester for pytest

Introduces start_race fixture to run race conditions tests.

Requirements

  • Python 2.7+, 3.3+

  • pytest 2.9.0+

Usage

You can use start_race fixture in your tests as follows:

from time import sleep

ACCUMULATOR = 0  # This global var is race conditions prone.

def test_race(start_race):
    from random import randint

    def actual_test():
        global ACCUMULATOR

        increment = randint(1, 10000)

        accumulator = ACCUMULATOR
        sleep(1)  # Simulate some lag.
        ACCUMULATOR += increment

        # By that moment ACCUMULATOR should have been updated
        # by another thread. Let's try to prove it.

        # Using simple `assert` as usual for pytest.
        assert accumulator + increment == ACCUMULATOR

    # Let's run `actual_test` in 2 threads.
    start_race(threads_num=2, target=actual_test)

start_race accepts the following arguments:

  • start_race - number of threads to run simultaneously.

  • start_race - actual test callable to run in threads.

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-race-0.1.0.tar.gz (4.6 kB view hashes)

Uploaded source

Built Distribution

pytest_race-0.1.0-py2.py3-none-any.whl (4.9 kB view hashes)

Uploaded 2 7

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