Be Patient#
bepatient is a library aimed at facilitating work with asynchronous applications. It allows for the repeated execution of specific actions until the desired effect is achieved.
Features#
- Set up and monitor requests for expected values.
- Flexible comparison using various checkers and comparers.
- Configure multiple conditions to be met by response.
- Inspect various aspects of the response (body, status code, headers).
- Detailed logs (containing cURLs), facilitating the analysis of the test process.
- Retry mechanism with customizable retries and delay.
Installation#
To install bepatient, you can use pip:
pip install bepatient
bepatient supports Python 3.10+
Basic Usage#
Using RequestsWaiter object:
from requests import get
from bepatient import RequestsWaiter
waiter = RequestsWaiter(request=get("https://example.com/api"))
waiter.add_checker(comparer="contain", expected_value="string")
waiter.run()
response = waiter.get_result()
assert response.status_code == 200
Simple way:
from requests import get
from bepatient import wait_for_value_in_request
response = wait_for_value_in_request(
    request=get("https://example.com/api"),
    comparer="contain",
    expected_value="string"
)
assert response.status_code == 200
If we need add more than one checker:
from requests import get
from bepatient import wait_for_values_in_request
list_of_checkers = [
    {
        "checker": "json_checker",
        "comparer": "contain",
        "expected_value": "string"
    },
    {
        "checker": "headers_checker",
        "comparer": "is_equal",
        "expected_value": "cloudflare",
        "dict_path": "Server",
    },
]
response = wait_for_values_in_request(
    request=get("https://example.com/api"),
    checkers=list_of_checkers,
    retries=5,
)
assert response.status_code == 200