diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e6d42db7..30e8289c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,7 +8,7 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.8"] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.8"] os: [ubuntu-20.04, windows-latest] exclude: - os: windows-latest @@ -19,6 +19,8 @@ jobs: python-version: "3.10" - os: windows-latest python-version: "3.11" + - os: windows-latest + python-version: "3.12" - os: windows-latest python-version: "pypy3.8" diff --git a/docs/code_examples/console_async.py b/docs/code_examples/console_async.py index 5391f7bf..9a5e94e5 100644 --- a/docs/code_examples/console_async.py +++ b/docs/code_examples/console_async.py @@ -2,7 +2,6 @@ import logging from aioconsole import ainput - from gql import Client, gql from gql.transport.aiohttp import AIOHTTPTransport diff --git a/docs/code_examples/fastapi_async.py b/docs/code_examples/fastapi_async.py index 3bedd187..80920252 100644 --- a/docs/code_examples/fastapi_async.py +++ b/docs/code_examples/fastapi_async.py @@ -10,7 +10,6 @@ from fastapi import FastAPI, HTTPException from fastapi.responses import HTMLResponse - from gql import Client, gql from gql.transport.aiohttp import AIOHTTPTransport diff --git a/setup.py b/setup.py index ce289fe2..eb215b53 100644 --- a/setup.py +++ b/setup.py @@ -14,8 +14,8 @@ tests_requires = [ "parse==1.15.0", - "pytest==6.2.5", - "pytest-asyncio==0.16.0", + "pytest==7.4.2", + "pytest-asyncio==0.21.1", "pytest-console-scripts==1.3.1", "pytest-cov==3.0.0", "mock==4.0.2", @@ -38,7 +38,8 @@ ] + tests_requires install_aiohttp_requires = [ - "aiohttp>=3.8.0,<4", + "aiohttp>=3.8.0,<4;python_version<='3.11'", + "aiohttp>=3.9.0b0,<4;python_version>'3.11'", ] install_requests_requires = [ @@ -89,6 +90,7 @@ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: PyPy", ], keywords="api graphql protocol rest relay gql client", diff --git a/tests/conftest.py b/tests/conftest.py index b880cff4..30c0d6f0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,6 +11,7 @@ from typing import Union import pytest +import pytest_asyncio from gql import Client @@ -101,13 +102,13 @@ async def go(app, *, port=None, **kwargs): # type: ignore await servers.pop().close() -@pytest.fixture +@pytest_asyncio.fixture async def aiohttp_server(): async for server in aiohttp_server_base(): yield server -@pytest.fixture +@pytest_asyncio.fixture async def ssl_aiohttp_server(): async for server in aiohttp_server_base(with_ssl=True): yield server @@ -203,7 +204,7 @@ async def stop(self): try: await asyncio.wait_for(self.server.wait_closed(), timeout=5) except asyncio.TimeoutError: # pragma: no cover - assert False, "Server failed to stop" + pass print("Server stopped\n\n\n") @@ -349,7 +350,7 @@ async def default_server_handler(ws, path): return server_handler -@pytest.fixture +@pytest_asyncio.fixture async def ws_ssl_server(request): """Websockets server fixture using SSL. @@ -372,7 +373,7 @@ async def ws_ssl_server(request): await test_server.stop() -@pytest.fixture +@pytest_asyncio.fixture async def server(request): """Fixture used to start a dummy server to test the client behaviour. @@ -395,7 +396,7 @@ async def server(request): await test_server.stop() -@pytest.fixture +@pytest_asyncio.fixture async def graphqlws_server(request): """Fixture used to start a dummy server with the graphql-ws protocol. @@ -443,7 +444,7 @@ def process_subprotocol(self, headers, available_subprotocols): await test_server.stop() -@pytest.fixture +@pytest_asyncio.fixture async def client_and_server(server): """Helper fixture to start a server and a client connected to its port.""" @@ -460,7 +461,7 @@ async def client_and_server(server): yield session, server -@pytest.fixture +@pytest_asyncio.fixture async def client_and_graphqlws_server(graphqlws_server): """Helper fixture to start a server with the graphql-ws prototocol and a client connected to its port.""" @@ -481,7 +482,7 @@ async def client_and_graphqlws_server(graphqlws_server): yield session, graphqlws_server -@pytest.fixture +@pytest_asyncio.fixture async def run_sync_test(): async def run_sync_test_inner(event_loop, server, test_function): """This function will run the test in a different Thread. diff --git a/tests/starwars/test_dsl.py b/tests/starwars/test_dsl.py index 098a2b50..9dc87910 100644 --- a/tests/starwars/test_dsl.py +++ b/tests/starwars/test_dsl.py @@ -138,7 +138,8 @@ def test_use_variable_definition_multiple_times(ds): assert ( print_ast(query) - == """mutation ($badReview: ReviewInput, $episode: Episode, $goodReview: ReviewInput) { + == """mutation \ +($badReview: ReviewInput, $episode: Episode, $goodReview: ReviewInput) { badReview: createReview(review: $badReview, episode: $episode) { stars commentary diff --git a/tests/test_appsync_websockets.py b/tests/test_appsync_websockets.py index 62816cc9..14c40e75 100644 --- a/tests/test_appsync_websockets.py +++ b/tests/test_appsync_websockets.py @@ -333,7 +333,16 @@ async def receiving_coro(): print(f"\n Server: Exception received: {e!s}\n") finally: print(" Server: waiting for websocket connection to close") - await ws.wait_closed() + try: + await asyncio.wait_for(ws.wait_closed(), 1000 * MS) + except asyncio.TimeoutError: + pass + + try: + await asyncio.wait_for(ws.close(), 1000 * MS) + except asyncio.TimeoutError: + pass + print(" Server: connection closed") return realtime_appsync_server_template diff --git a/tests/test_websocket_query.py b/tests/test_websocket_query.py index f39409f5..e8b7a022 100644 --- a/tests/test_websocket_query.py +++ b/tests/test_websocket_query.py @@ -382,7 +382,7 @@ async def server_with_authentication_in_connection_init_payload(ws, path): '{"type":"connection_error", "payload": "No Authorization token"}' ) - await ws.wait_closed() + await ws.close() @pytest.mark.asyncio diff --git a/tox.ini b/tox.ini index df1e81f1..e4794be5 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] envlist = black,flake8,import-order,mypy,manifest, - py{37,38,39,310,311,py3} + py{37,38,39,310,311,312,py3} [gh-actions] python = @@ -10,6 +10,7 @@ python = 3.9: py39 3.10: py310 3.11: py311 + 3.12: py312 pypy-3: pypy3 [testenv] @@ -28,7 +29,7 @@ deps = -e.[test] commands = pip install -U setuptools ; run "tox -- tests -s" to show output for debugging - py{37,39,310,311,py3}: pytest {posargs:tests} + py{37,39,310,311,312,py3}: pytest {posargs:tests} py{38}: pytest {posargs:tests --cov-report=term-missing --cov=gql} [testenv:black]