Skip to content

Commit e0bd497

Browse files
authored
Fix tests with Python 3.12 (#442)
* Adding Python 3.12 to automated tests * Bumping `pytest` and `pytest_asyncio` versions * Fixing test cleanup for Python 3.12 * Force aiohttp 3.9.0b0 version for Python version >= 3.12
1 parent c939573 commit e0bd497

File tree

9 files changed

+34
-20
lines changed

9 files changed

+34
-20
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
max-parallel: 4
1010
matrix:
11-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.8"]
11+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.8"]
1212
os: [ubuntu-20.04, windows-latest]
1313
exclude:
1414
- os: windows-latest
@@ -19,6 +19,8 @@ jobs:
1919
python-version: "3.10"
2020
- os: windows-latest
2121
python-version: "3.11"
22+
- os: windows-latest
23+
python-version: "3.12"
2224
- os: windows-latest
2325
python-version: "pypy3.8"
2426

docs/code_examples/console_async.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import logging
33

44
from aioconsole import ainput
5-
65
from gql import Client, gql
76
from gql.transport.aiohttp import AIOHTTPTransport
87

docs/code_examples/fastapi_async.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from fastapi import FastAPI, HTTPException
1212
from fastapi.responses import HTMLResponse
13-
1413
from gql import Client, gql
1514
from gql.transport.aiohttp import AIOHTTPTransport
1615

setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
tests_requires = [
1616
"parse==1.15.0",
17-
"pytest==6.2.5",
18-
"pytest-asyncio==0.16.0",
17+
"pytest==7.4.2",
18+
"pytest-asyncio==0.21.1",
1919
"pytest-console-scripts==1.3.1",
2020
"pytest-cov==3.0.0",
2121
"mock==4.0.2",
@@ -38,7 +38,8 @@
3838
] + tests_requires
3939

4040
install_aiohttp_requires = [
41-
"aiohttp>=3.8.0,<4",
41+
"aiohttp>=3.8.0,<4;python_version<='3.11'",
42+
"aiohttp>=3.9.0b0,<4;python_version>'3.11'",
4243
]
4344

4445
install_requests_requires = [
@@ -89,6 +90,7 @@
8990
"Programming Language :: Python :: 3.9",
9091
"Programming Language :: Python :: 3.10",
9192
"Programming Language :: Python :: 3.11",
93+
"Programming Language :: Python :: 3.12",
9294
"Programming Language :: Python :: Implementation :: PyPy",
9395
],
9496
keywords="api graphql protocol rest relay gql client",

tests/conftest.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import Union
1212

1313
import pytest
14+
import pytest_asyncio
1415

1516
from gql import Client
1617

@@ -101,13 +102,13 @@ async def go(app, *, port=None, **kwargs): # type: ignore
101102
await servers.pop().close()
102103

103104

104-
@pytest.fixture
105+
@pytest_asyncio.fixture
105106
async def aiohttp_server():
106107
async for server in aiohttp_server_base():
107108
yield server
108109

109110

110-
@pytest.fixture
111+
@pytest_asyncio.fixture
111112
async def ssl_aiohttp_server():
112113
async for server in aiohttp_server_base(with_ssl=True):
113114
yield server
@@ -203,7 +204,7 @@ async def stop(self):
203204
try:
204205
await asyncio.wait_for(self.server.wait_closed(), timeout=5)
205206
except asyncio.TimeoutError: # pragma: no cover
206-
assert False, "Server failed to stop"
207+
pass
207208

208209
print("Server stopped\n\n\n")
209210

@@ -349,7 +350,7 @@ async def default_server_handler(ws, path):
349350
return server_handler
350351

351352

352-
@pytest.fixture
353+
@pytest_asyncio.fixture
353354
async def ws_ssl_server(request):
354355
"""Websockets server fixture using SSL.
355356
@@ -372,7 +373,7 @@ async def ws_ssl_server(request):
372373
await test_server.stop()
373374

374375

375-
@pytest.fixture
376+
@pytest_asyncio.fixture
376377
async def server(request):
377378
"""Fixture used to start a dummy server to test the client behaviour.
378379
@@ -395,7 +396,7 @@ async def server(request):
395396
await test_server.stop()
396397

397398

398-
@pytest.fixture
399+
@pytest_asyncio.fixture
399400
async def graphqlws_server(request):
400401
"""Fixture used to start a dummy server with the graphql-ws protocol.
401402
@@ -443,7 +444,7 @@ def process_subprotocol(self, headers, available_subprotocols):
443444
await test_server.stop()
444445

445446

446-
@pytest.fixture
447+
@pytest_asyncio.fixture
447448
async def client_and_server(server):
448449
"""Helper fixture to start a server and a client connected to its port."""
449450

@@ -460,7 +461,7 @@ async def client_and_server(server):
460461
yield session, server
461462

462463

463-
@pytest.fixture
464+
@pytest_asyncio.fixture
464465
async def client_and_graphqlws_server(graphqlws_server):
465466
"""Helper fixture to start a server with the graphql-ws prototocol
466467
and a client connected to its port."""
@@ -481,7 +482,7 @@ async def client_and_graphqlws_server(graphqlws_server):
481482
yield session, graphqlws_server
482483

483484

484-
@pytest.fixture
485+
@pytest_asyncio.fixture
485486
async def run_sync_test():
486487
async def run_sync_test_inner(event_loop, server, test_function):
487488
"""This function will run the test in a different Thread.

tests/starwars/test_dsl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ def test_use_variable_definition_multiple_times(ds):
138138

139139
assert (
140140
print_ast(query)
141-
== """mutation ($badReview: ReviewInput, $episode: Episode, $goodReview: ReviewInput) {
141+
== """mutation \
142+
($badReview: ReviewInput, $episode: Episode, $goodReview: ReviewInput) {
142143
badReview: createReview(review: $badReview, episode: $episode) {
143144
stars
144145
commentary

tests/test_appsync_websockets.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,16 @@ async def receiving_coro():
333333
print(f"\n Server: Exception received: {e!s}\n")
334334
finally:
335335
print(" Server: waiting for websocket connection to close")
336-
await ws.wait_closed()
336+
try:
337+
await asyncio.wait_for(ws.wait_closed(), 1000 * MS)
338+
except asyncio.TimeoutError:
339+
pass
340+
341+
try:
342+
await asyncio.wait_for(ws.close(), 1000 * MS)
343+
except asyncio.TimeoutError:
344+
pass
345+
337346
print(" Server: connection closed")
338347

339348
return realtime_appsync_server_template

tests/test_websocket_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ async def server_with_authentication_in_connection_init_payload(ws, path):
382382
'{"type":"connection_error", "payload": "No Authorization token"}'
383383
)
384384

385-
await ws.wait_closed()
385+
await ws.close()
386386

387387

388388
@pytest.mark.asyncio

tox.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tox]
22
envlist =
33
black,flake8,import-order,mypy,manifest,
4-
py{37,38,39,310,311,py3}
4+
py{37,38,39,310,311,312,py3}
55

66
[gh-actions]
77
python =
@@ -10,6 +10,7 @@ python =
1010
3.9: py39
1111
3.10: py310
1212
3.11: py311
13+
3.12: py312
1314
pypy-3: pypy3
1415

1516
[testenv]
@@ -28,7 +29,7 @@ deps = -e.[test]
2829
commands =
2930
pip install -U setuptools
3031
; run "tox -- tests -s" to show output for debugging
31-
py{37,39,310,311,py3}: pytest {posargs:tests}
32+
py{37,39,310,311,312,py3}: pytest {posargs:tests}
3233
py{38}: pytest {posargs:tests --cov-report=term-missing --cov=gql}
3334

3435
[testenv:black]

0 commit comments

Comments
 (0)