Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/idlesign/pytest-race
Race conditions tester for pytest
https://github.com/idlesign/pytest-race
Last synced: 4 days ago
JSON representation
Race conditions tester for pytest
- Host: GitHub
- URL: https://github.com/idlesign/pytest-race
- Owner: idlesign
- License: bsd-3-clause
- Created: 2016-11-20T12:29:49.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-06-07T14:38:08.000Z (over 2 years ago)
- Last Synced: 2024-11-02T11:42:02.607Z (11 days ago)
- Language: Python
- Homepage: https://github.com/idlesign/pytest-race
- Size: 23.4 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG
- License: LICENSE
Awesome Lists containing this project
README
pytest-race
===========
https://github.com/idlesign/pytest-race.. image:: https://img.shields.io/pypi/v/pytest-race.svg
:target: https://pypi.python.org/pypi/pytest-race.. image:: https://img.shields.io/pypi/dm/pytest-race.svg
:target: https://pypi.python.org/pypi/pytest-race.. image:: https://img.shields.io/pypi/l/pytest-race.svg
:target: https://pypi.python.org/pypi/pytest-race.. image:: https://img.shields.io/coveralls/idlesign/pytest-race/master.svg
:target: https://coveralls.io/r/idlesign/pytest-raceDescription
-----------*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:
.. code-block:: python
from time import sleep
ACCUMULATOR = 0 # This global var is race conditions prone.
def test_race(start_race):
from random import randintdef actual_test():
global ACCUMULATORincrement = 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.