Skip to content

Commit 00f7e11

Browse files
committed
Fix running tests on python 3.14
See #3664 See #3616
1 parent 0a1591e commit 00f7e11

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ filterwarnings = [
120120
"error",
121121
"ignore: You seem to already have a custom sys.excepthook handler installed. I'll skip installing Trio's custom handler, but this means MultiErrors will not show full tracebacks.:RuntimeWarning",
122122
# See: https://github.com/agronholm/anyio/issues/508
123-
"ignore: trio.MultiError is deprecated since Trio 0.22.0:trio.TrioDeprecationWarning"
123+
"ignore: trio.MultiError is deprecated since Trio 0.22.0:trio.TrioDeprecationWarning",
124+
# Python 3.14 deprecates asyncio.iscoroutinefunction, but uvicorn 0.35.0 still uses it
125+
"ignore: 'asyncio.iscoroutinefunction' is deprecated:DeprecationWarning"
124126
]
125127
markers = [
126128
"copied_from(source, changes=None): mark test as copied from somewhere else, along with a description of changes made to accodomate e.g. our test setup",

tests/conftest.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,9 @@ def install_signal_handlers(self) -> None:
235235
async def serve(self, sockets=None):
236236
self.restart_requested = asyncio.Event()
237237

238-
loop = asyncio.get_event_loop()
239238
tasks = {
240-
loop.create_task(super().serve(sockets=sockets)),
241-
loop.create_task(self.watch_restarts()),
239+
asyncio.create_task(super().serve(sockets=sockets)),
240+
asyncio.create_task(self.watch_restarts()),
242241
}
243242
await asyncio.wait(tasks)
244243

@@ -269,7 +268,15 @@ async def watch_restarts(self) -> None: # pragma: no cover
269268

270269

271270
def serve_in_thread(server: TestServer) -> typing.Iterator[TestServer]:
272-
thread = threading.Thread(target=server.run)
271+
def run_server():
272+
# Manually set up event loop for Python 3.14 compatibility
273+
loop = asyncio.new_event_loop()
274+
asyncio.set_event_loop(loop)
275+
server.config.setup_event_loop()
276+
loop.run_until_complete(server.serve())
277+
loop.close()
278+
279+
thread = threading.Thread(target=run_server)
273280
thread.start()
274281
try:
275282
while not server.started:
@@ -282,6 +289,6 @@ def serve_in_thread(server: TestServer) -> typing.Iterator[TestServer]:
282289

283290
@pytest.fixture(scope="session")
284291
def server() -> typing.Iterator[TestServer]:
285-
config = Config(app=app, lifespan="off", loop="asyncio")
292+
config = Config(app=app, lifespan="off")
286293
server = TestServer(config=config)
287294
yield from serve_in_thread(server)

0 commit comments

Comments
 (0)