Skip to main content

Race conditions tester for pytest

Project description


Race conditions tester for pytest

Introduces start_race fixture to run race condition tests.


  • Python 2.7+, 3.3+
  • pytest 2.9.0+


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:

  • threads_num - number of threads to run simultaneously.
  • target - 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.

Files for pytest-race, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size pytest_race-0.1.1-py2.py3-none-any.whl (4.9 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size pytest-race-0.1.1.tar.gz (4.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page