Easy and expressive busy-waiting for Python
Project description
Easy and expressive busy-waiting for Python
Intro
Although you wouldn't want to do much busy waiting in your production code, testing is a different matter. When testing asynchronous systems, it's very helpful to wait for some scenario to finish its course. BusyPie helps you perform busy waiting easily and expressively.
Installation
To install it using pip
python -m pip install busypie
To include it in requirements.txt file add
busypie==0.4.2
Example
Most typical usage will be in test, when we have a scenario that require us to wait for something to happen.
def test_event_should_be_dispatched():
dispatcher.dispatch(event)
wait().at_most(2, SECOND).until(event_dispatched)
Usage
Wait for a condition. Default wait time is 10 seconds. until() will return the final result of the condition function
wait().until(condition_function)
wait().during(condition_function)
Python async support. until_async() will return the final result of the condition function.
await wait().until_async(condition_function)
await wait().during_async(condition_function)
Specify maximum time to meet the condition
wait().at_most(FIVE_SECONDS).until(condition_function)
wait_at_most(FIVE_SECONDS).until(condition_function)
wait().at_most(10, SECOND).until(condition_function)
wait_at_most(10, SECOND).until(condition_function)
Ignoring exceptions thrown from a condition function
given().ignore_exceptions().wait().until(condition_function)
wait().ignore_exceptions(ZeroDevisionError).until(condition_function)
Add custom description to show up in timeout error message
wait().with_description('check app is running').until(lambda: app_state() == 'UP')
Changing poll interval
wait().poll_interval(FIVE_HUNDRED_MILLISECONDS).until(condition_function)
wait().poll_interval(2, SECOND).until(condition_function)
Changing polling delay
wait().poll_delay(SECOND).during(app_is_pending)
Changing the default values of busypie
set_default_timeout(60, SECOND) # Default is 10 seconds
Resetting default values
reset_defaults()
Credits
This project drew a lot of inspiration from Awaitility.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.