diff --git a/swh/core/api/tests/test_async.py b/swh/core/api/tests/test_async.py --- a/swh/core/api/tests/test_async.py +++ b/swh/core/api/tests/test_async.py @@ -96,10 +96,12 @@ return app -async def test_get_simple(async_app, aiohttp_client) -> None: - assert async_app is not None +@pytest.fixture +def cli(async_app, aiohttp_client, loop): + return loop.run_until_complete(aiohttp_client(async_app)) + - cli = await aiohttp_client(async_app) +async def test_get_simple(cli) -> None: resp = await cli.get("/") assert resp.status == 200 check_mimetype(resp.headers["Content-Type"], "application/x-msgpack") @@ -108,8 +110,7 @@ assert value == "toor" -async def test_get_server_exception(async_app, aiohttp_client) -> None: - cli = await aiohttp_client(async_app) +async def test_get_server_exception(cli) -> None: resp = await cli.get("/server_exception") assert resp.status == 500 data = await resp.read() @@ -117,8 +118,7 @@ assert data["exception"]["type"] == "TestServerException" -async def test_get_client_error(async_app, aiohttp_client) -> None: - cli = await aiohttp_client(async_app) +async def test_get_client_error(cli) -> None: resp = await cli.get("/client_error") assert resp.status == 400 data = await resp.read() @@ -126,8 +126,7 @@ assert data["exception"]["type"] == "TestClientError" -async def test_get_simple_nego(async_app, aiohttp_client) -> None: - cli = await aiohttp_client(async_app) +async def test_get_simple_nego(cli) -> None: for ctype in ("x-msgpack", "json"): resp = await cli.get("/", headers={"Accept": "application/%s" % ctype}) assert resp.status == 200 @@ -135,18 +134,16 @@ assert (await decode_request(resp)) == "toor" -async def test_get_struct(async_app, aiohttp_client) -> None: +async def test_get_struct(cli) -> None: """Test returned structured from a simple GET data is OK""" - cli = await aiohttp_client(async_app) resp = await cli.get("/struct") assert resp.status == 200 check_mimetype(resp.headers["Content-Type"], "application/x-msgpack") assert (await decode_request(resp)) == STRUCT -async def test_get_struct_nego(async_app, aiohttp_client) -> None: +async def test_get_struct_nego(cli) -> None: """Test returned structured from a simple GET data is OK""" - cli = await aiohttp_client(async_app) for ctype in ("x-msgpack", "json"): resp = await cli.get("/struct", headers={"Accept": "application/%s" % ctype}) assert resp.status == 200 @@ -154,9 +151,8 @@ assert (await decode_request(resp)) == STRUCT -async def test_post_struct_msgpack(async_app, aiohttp_client) -> None: +async def test_post_struct_msgpack(cli) -> None: """Test that msgpack encoded posted struct data is returned as is""" - cli = await aiohttp_client(async_app) # simple struct resp = await cli.post( "/echo", @@ -177,10 +173,8 @@ assert (await decode_request(resp)) == STRUCT -async def test_post_struct_json(async_app, aiohttp_client) -> None: +async def test_post_struct_json(cli) -> None: """Test that json encoded posted struct data is returned as is""" - cli = await aiohttp_client(async_app) - resp = await cli.post( "/echo", headers={"Content-Type": "application/json"}, @@ -201,13 +195,11 @@ assert (await decode_request(resp)) == STRUCT -async def test_post_struct_nego(async_app, aiohttp_client) -> None: +async def test_post_struct_nego(cli) -> None: """Test that json encoded posted struct data is returned as is using content negotiation (accept json or msgpack). """ - cli = await aiohttp_client(async_app) - for ctype in ("x-msgpack", "json"): resp = await cli.post( "/echo", @@ -222,13 +214,11 @@ assert (await decode_request(resp)) == STRUCT -async def test_post_struct_no_nego(async_app, aiohttp_client) -> None: +async def test_post_struct_no_nego(cli) -> None: """Test that json encoded posted struct data is returned as msgpack when using non-negotiation-compatible handlers. """ - cli = await aiohttp_client(async_app) - for ctype in ("x-msgpack", "json"): resp = await cli.post( "/echo-no-nego",