test/api: replace use of deprecated "with timeout()"

Running the API tests in Ubuntu 22.04 or newer versions result in the
following warning:

 DeprecationWarning: with timeout() is deprecated, use async with
 timeout() instead

The deprecation message was introduced as part of async-timeout 4.0.0

The ability to use async_timeout.timeout as an async context manager
was introduced in version 1.3.0 in 2017 so there is no problem using it.

The version of python3-async-timeout present in the archives at the time
of writing is:

 * 4.0.1 in jammy
 * 3.0.1 in focal
 * 2.0.0 in bionic

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2022-06-22 10:03:28 +02:00
parent c4af1a09cf
commit 50315b991b
1 changed files with 1 additions and 1 deletions

View File

@ -36,7 +36,7 @@ def timeout(multiplier=1):
def wrapper(coro): def wrapper(coro):
@wraps(coro) @wraps(coro)
async def run(*args, **kwargs): async def run(*args, **kwargs):
with async_timeout.timeout(default_timeout * multiplier): async with async_timeout.timeout(default_timeout * multiplier):
return await coro(*args, **kwargs) return await coro(*args, **kwargs)
return run return run
return wrapper return wrapper