admin管理员组

文章数量:1122832

I'm testing asynchronous code using PyTest.

Can't find any existing libraries that provide simple function like "Await until" or "Polling":

operation.run_in_background()

await_until(lambda: operation.is_ready(), interval=1, timeout=10)

It's easy to implement such function, but I believe there is a ready library for this.

Thank you.

I'm testing asynchronous code using PyTest.

Can't find any existing libraries that provide simple function like "Await until" or "Polling":

operation.run_in_background()

await_until(lambda: operation.is_ready(), interval=1, timeout=10)

It's easy to implement such function, but I believe there is a ready library for this.

Thank you.

Share Improve this question edited yesterday Aleks Ya asked yesterday Aleks YaAleks Ya 9095 gold badges15 silver badges32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

polling might be a good fit for you.

operation.run_in_background()
timeout_s = 10
interval_s = 1
try:
    polling.poll(
        lambda: operation.is_ready(),
        timeout=timeout_s,
        step=interval_s
    )
except polling.TimeoutException:
    pytest.fail(f"Operation could not be completed within {timeout_s}s.")

本文标签: pythonWaitUntil strategy in PyTestStack Overflow