Skip to content

Commit 4771aaf

Browse files
author
Sylvain MARIE
committed
Changed the fix to leverage pytest-asyncio, now that we do not support python <3.9 anymore
1 parent 498ed69 commit 4771aaf

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

docs/changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
### 1.16.0 - (in progress) new python versions scope
44

55
- Removed official support for python versions `<3.9`. These versions will not run in CI anymore.
6-
- Fixed `RuntimeError` in tests when running on pythn 3.14. Added python 3.14 to CI. Fixes [#112](https://github.com/smarie/python-makefun/issues/112)
6+
- Fixed `RuntimeError` in tests when running on python 3.14. Added python 3.14 to CI. Fixes
7+
[#112](https://github.com/smarie/python-makefun/issues/112)
78

89
### 1.15.6 - compatibility fix
910

setup.cfg

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ classifiers =
1919
License :: OSI Approved :: BSD License
2020
Topic :: Software Development :: Libraries :: Python Modules
2121
Programming Language :: Python
22-
Programming Language :: Python :: 2
23-
Programming Language :: Python :: 2.7
24-
Programming Language :: Python :: 3
25-
Programming Language :: Python :: 3.5
26-
Programming Language :: Python :: 3.6
27-
Programming Language :: Python :: 3.7
28-
Programming Language :: Python :: 3.8
2922
Programming Language :: Python :: 3.9
3023
Programming Language :: Python :: 3.10
3124
Programming Language :: Python :: 3.11
@@ -41,6 +34,7 @@ install_requires =
4134
funcsigs;python_version<'3.3'
4235
tests_require =
4336
pytest
37+
pytest-asyncio
4438
# for some reason these pytest dependencies were not declared in old versions of pytest
4539
six;python_version<'3.6'
4640
attr;python_version<'3.6'

tests/test_generators_coroutines.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def my_gencoroutine_handler(first_msg):
7676

7777

7878
@pytest.mark.skipif(sys.version_info < (3, 5), reason="native coroutines with async/await require python3.6 or higher")
79-
def test_native_coroutine():
79+
async def test_native_coroutine():
8080
""" Tests that we can use a native async coroutine as function_handler in `create_function`"""
8181

8282
# define the handler that should be called
@@ -92,13 +92,12 @@ def test_native_coroutine():
9292
assert is_native_co(dynamic_fun)
9393

9494
# verify that the new function is a native coroutine and behaves correctly
95-
from asyncio import run
96-
out = run(dynamic_fun(0.1))
95+
out = await dynamic_fun(0.1)
9796
assert out == 0.1
9897

9998

10099
@pytest.mark.skipif(sys.version_info < (3, 5), reason="native coroutines with async/await require python3.6 or higher")
101-
def test_issue_96():
100+
async def test_issue_96():
102101
"""Same as `test_native_coroutine` but tests that we can use 'return' in the coroutine name"""
103102

104103
# define the handler that should be called
@@ -114,6 +113,5 @@ def test_issue_96():
114113
assert is_native_co(dynamic_fun)
115114

116115
# verify that the new function is a native coroutine and behaves correctly
117-
from asyncio import run
118-
out = run(dynamic_fun(0.1))
116+
out = await dynamic_fun(0.1)
119117
assert out == 0.1

tests/test_issues.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def f(a):
228228

229229

230230
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python 3.6 or higher (async generator)")
231-
def test_issue_77_async_generator_wraps():
231+
async def test_issue_77_async_generator_wraps():
232232
import asyncio
233233
from ._test_py36 import make_async_generator, make_async_generator_wrapper
234234

@@ -238,11 +238,12 @@ def test_issue_77_async_generator_wraps():
238238
assert inspect.isasyncgenfunction(f)
239239
assert inspect.isasyncgenfunction(wrapper)
240240

241-
assert asyncio.get_event_loop().run_until_complete(asyncio.ensure_future(wrapper(1).__anext__())) == 1
241+
out = await asyncio.ensure_future(wrapper(1).__anext__())
242+
assert out == 1
242243

243244

244245
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python 3.6 or higher (async generator)")
245-
def test_issue_77_async_generator_partial():
246+
async def test_issue_77_async_generator_partial():
246247
import asyncio
247248
from ._test_py36 import make_async_generator
248249

@@ -252,7 +253,8 @@ def test_issue_77_async_generator_partial():
252253
assert inspect.isasyncgenfunction(f)
253254
assert inspect.isasyncgenfunction(f_partial)
254255

255-
assert asyncio.get_event_loop().run_until_complete(asyncio.ensure_future(f_partial().__anext__())) == 1
256+
out = await asyncio.ensure_future(f_partial().__anext__())
257+
assert out == 1
256258

257259

258260
@pytest.mark.skipif(sys.version_info < (3, 7, 6), reason="The __wrapped__ behavior in get_type_hints being tested was not added until python 3.7.6.")

0 commit comments

Comments
 (0)