at master 3.3 kB view raw
1From af9b471eba92f1f353fec57f60e48702e79bcb80 Mon Sep 17 00:00:00 2001 2From: Martin Weinelt <hexa@darmstadt.ccc.de> 3Date: Thu, 21 Aug 2025 15:24:37 +0200 4Subject: [PATCH] Fix tests with pytest 8.4 5 6Pytest 8.4 will fail on async functions, if they are not handled by a 7plugin. And since pytest-aiohttp relies on pytest-asyncio, the obvious 8fix is to mark them as asyncio. 9--- 10 tests.py | 11 +++++++++++ 11 1 file changed, 11 insertions(+) 12 13diff --git a/tests.py b/tests.py 14index e11c4d5..547d636 100644 15--- a/tests.py 16+++ b/tests.py 17@@ -11,6 +11,7 @@ 18 from jsonrpc_async import Server, ProtocolError, TransportError 19 20 21+@pytest.mark.asyncio 22 async def test_send_message_timeout(aiohttp_client): 23 """Test the catching of the timeout responses.""" 24 25@@ -37,6 +38,7 @@ def create_app(): 26 assert isinstance(transport_error.value.args[1], asyncio.TimeoutError) 27 28 29+@pytest.mark.asyncio 30 async def test_send_message(aiohttp_client): 31 """Test the sending of messages.""" 32 # catch non-json responses 33@@ -100,6 +102,7 @@ def create_app(): 34 "Error calling method 'my_method': Transport Error") 35 36 37+@pytest.mark.asyncio 38 async def test_exception_passthrough(aiohttp_client): 39 async def callback(*args, **kwargs): 40 raise aiohttp.ClientOSError('aiohttp exception') 41@@ -120,6 +123,7 @@ def create_app(): 42 assert isinstance(transport_error.value.args[1], aiohttp.ClientOSError) 43 44 45+@pytest.mark.asyncio 46 async def test_forbid_private_methods(aiohttp_client): 47 """Test that we can't call private methods (those starting with '_').""" 48 def create_app(): 49@@ -137,6 +141,7 @@ def create_app(): 50 await server.foo.bar._baz() 51 52 53+@pytest.mark.asyncio 54 async def test_headers_passthrough(aiohttp_client): 55 """Test that we correctly send RFC headers and merge them with users.""" 56 async def handler(request): 57@@ -170,6 +175,7 @@ async def callback(*args, **kwargs): 58 await server.foo() 59 60 61+@pytest.mark.asyncio 62 async def test_method_call(aiohttp_client): 63 """Mixing *args and **kwargs is forbidden by the spec.""" 64 def create_app(): 65@@ -185,6 +191,7 @@ def create_app(): 66 "JSON-RPC spec forbids mixing arguments and keyword arguments") 67 68 69+@pytest.mark.asyncio 70 async def test_method_nesting(aiohttp_client): 71 """Test that we correctly nest namespaces.""" 72 async def handler(request): 73@@ -211,6 +218,7 @@ def create_app(): 74 "nest.testmethod.some.other.method") is True 75 76 77+@pytest.mark.asyncio 78 async def test_calls(aiohttp_client): 79 """Test RPC call with positional parameters.""" 80 async def handler1(request): 81@@ -265,6 +273,7 @@ def create_app(): 82 await server.foobar({'foo': 'bar'}) 83 84 85+@pytest.mark.asyncio 86 async def test_notification(aiohttp_client): 87 """Verify that we ignore the server response.""" 88 async def handler(request): 89@@ -283,6 +292,7 @@ def create_app(): 90 assert await server.subtract(42, 23, _notification=True) is None 91 92 93+@pytest.mark.asyncio 94 async def test_custom_loads(aiohttp_client): 95 """Test RPC call with custom load.""" 96 loads_mock = mock.Mock(wraps=json.loads) 97@@ -306,6 +316,7 @@ def create_app(): 98 assert loads_mock.call_count == 1 99 100 101+@pytest.mark.asyncio 102 async def test_context_manager(aiohttp_client): 103 # catch non-json responses 104 async def handler1(request):