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

Description

Race conditions tester for pytest

Introduces start_race fixture to run race condition tests.

Requirements

  • Python 3.7+

  • 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:

  • 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.

Source Distribution

pytest-race-0.2.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

pytest_race-0.2.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file pytest-race-0.2.0.tar.gz.

File metadata

  • Download URL: pytest-race-0.2.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.8

File hashes

Hashes for pytest-race-0.2.0.tar.gz
Algorithm Hash digest
SHA256 92a43179ece42366ae2207bf4160bdb64781dc2ca425d1b37dc310c58ad0ade3
MD5 6681f966687b26a4975241814a8dba10
BLAKE2b-256 2119aaec2ab5958304d74d8899e12e72987f17787f0c64c1b53873c7ff568089

See more details on using hashes here.

File details

Details for the file pytest_race-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_race-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2ae6cf1feece53619a76534a38863565b95f91436e78fb1bc7090234317eaf9
MD5 f4db52e5c12fe7a136009055d8a98c2c
BLAKE2b-256 04f2d30028f66885ae12ff210d35c93f827828b1c2d213d51d5f06b32ba3e8a5

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