Skip to content

Commit 28bc090

Browse files
committed
Make things work on latest pytest-asyncio
1 parent f115733 commit 28bc090

4 files changed

Lines changed: 24 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ Homepage = "https://github.com/bmerry/async-solipsism"
2323

2424
[project.optional-dependencies]
2525
test = [
26+
"backports.asyncio.runner; python_version<'3.11'",
2627
"pre-commit",
2728
"pytest",
28-
"pytest-asyncio>=0.23,<1.0",
29+
"pytest-asyncio>=0.23",
2930
"pytest-mock",
3031
]
3132

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file was autogenerated by uv via the following command:
22
# uv pip compile --python-version=3.10 --universal --output-file=requirements.txt --extra=test pyproject.toml
3+
backports-asyncio-runner==1.2.0 ; python_full_version < '3.11'
4+
# via async-solipsism (pyproject.toml)
35
cfgv==3.5.0
46
# via pre-commit
57
colorama==0.4.6 ; sys_platform == 'win32'

src/async_solipsism/loop.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,17 @@ def _stop_serving(self, sock):
219219
self.__listening_sockets.pop(addr)
220220
super()._stop_serving(sock)
221221

222+
async def shutdown_default_executor(self, timeout=None):
223+
# The default implementation uses an asyncio timeout, which
224+
# would complete immediately without giving the executor
225+
# time to shut down. We ignore the timeout and just shut
226+
# things down synchronously. This is based on the code in
227+
# CPython.
228+
self._executor_shutdown_called = True
229+
if self._default_executor is None:
230+
return
231+
self._default_executor.shutdown(wait=True)
232+
222233

223234
class EventLoopPolicy(asyncio.DefaultEventLoopPolicy):
224235
def new_event_loop(self) -> EventLoop:

test/test_loop.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717

1818
import asyncio
1919
import concurrent.futures
20+
import sys
2021
import threading
22+
if sys.version_info < (3, 11):
23+
from backports.asyncio.runner import Runner
24+
else:
25+
from asyncio import Runner
2126

2227
import pytest
2328

@@ -36,12 +41,13 @@ async def test_sleep():
3641
assert event_loop.time() == 2.0
3742

3843

39-
def test_sleep_forever(event_loop):
44+
def test_sleep_forever():
4045
async def zzz():
4146
await asyncio.Future()
4247

43-
with pytest.raises(async_solipsism.SleepForeverError):
44-
event_loop.run_until_complete(zzz())
48+
with Runner(loop_factory=async_solipsism.EventLoop) as runner:
49+
with pytest.raises(async_solipsism.SleepForeverError):
50+
runner.run(zzz())
4551

4652

4753
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)