6
6
import pytest_asyncio .plugin
7
7
8
8
9
- @asyncio .coroutine
10
- def async_coro (loop = None ):
9
+ async def async_coro (loop = None ):
11
10
"""A very simple coroutine."""
12
- yield from asyncio .sleep (0 , loop = loop )
11
+ await asyncio .sleep (0 , loop = loop )
13
12
return 'ok'
14
13
15
14
@@ -53,66 +52,64 @@ def test_asyncio_marker_with_default_param(a_param=None):
53
52
54
53
55
54
@pytest .mark .asyncio_process_pool
56
- def test_asyncio_process_pool_marker (event_loop ):
55
+ async def test_asyncio_process_pool_marker (event_loop ):
57
56
"""Test the asyncio pytest marker."""
58
- ret = yield from async_coro (event_loop )
57
+ ret = await async_coro (event_loop )
59
58
assert ret == 'ok'
60
59
61
60
62
61
@pytest .mark .asyncio
63
- def test_unused_port_fixture (unused_tcp_port , event_loop ):
62
+ async def test_unused_port_fixture (unused_tcp_port , event_loop ):
64
63
"""Test the unused TCP port fixture."""
65
64
66
- @asyncio .coroutine
67
- def closer (_ , writer ):
65
+ async def closer (_ , writer ):
68
66
writer .close ()
69
67
70
- server1 = yield from asyncio .start_server (closer , host = 'localhost' ,
71
- port = unused_tcp_port ,
72
- loop = event_loop )
68
+ server1 = await asyncio .start_server (closer , host = 'localhost' ,
69
+ port = unused_tcp_port ,
70
+ loop = event_loop )
73
71
74
72
with pytest .raises (IOError ):
75
- yield from asyncio .start_server (closer , host = 'localhost' ,
76
- port = unused_tcp_port ,
77
- loop = event_loop )
73
+ await asyncio .start_server (closer , host = 'localhost' ,
74
+ port = unused_tcp_port ,
75
+ loop = event_loop )
78
76
79
77
server1 .close ()
80
- yield from server1 .wait_closed ()
78
+ await server1 .wait_closed ()
81
79
82
80
83
81
@pytest .mark .asyncio
84
- def test_unused_port_factory_fixture (unused_tcp_port_factory , event_loop ):
82
+ async def test_unused_port_factory_fixture (unused_tcp_port_factory , event_loop ):
85
83
"""Test the unused TCP port factory fixture."""
86
84
87
- @asyncio .coroutine
88
- def closer (_ , writer ):
85
+ async def closer (_ , writer ):
89
86
writer .close ()
90
87
91
88
port1 , port2 , port3 = (unused_tcp_port_factory (), unused_tcp_port_factory (),
92
89
unused_tcp_port_factory ())
93
90
94
- server1 = yield from asyncio .start_server (closer , host = 'localhost' ,
95
- port = port1 ,
96
- loop = event_loop )
97
- server2 = yield from asyncio .start_server (closer , host = 'localhost' ,
98
- port = port2 ,
99
- loop = event_loop )
100
- server3 = yield from asyncio .start_server (closer , host = 'localhost' ,
101
- port = port3 ,
102
- loop = event_loop )
91
+ server1 = await asyncio .start_server (closer , host = 'localhost' ,
92
+ port = port1 ,
93
+ loop = event_loop )
94
+ server2 = await asyncio .start_server (closer , host = 'localhost' ,
95
+ port = port2 ,
96
+ loop = event_loop )
97
+ server3 = await asyncio .start_server (closer , host = 'localhost' ,
98
+ port = port3 ,
99
+ loop = event_loop )
103
100
104
101
for port in port1 , port2 , port3 :
105
102
with pytest .raises (IOError ):
106
- yield from asyncio .start_server (closer , host = 'localhost' ,
107
- port = port ,
108
- loop = event_loop )
103
+ await asyncio .start_server (closer , host = 'localhost' ,
104
+ port = port ,
105
+ loop = event_loop )
109
106
110
107
server1 .close ()
111
- yield from server1 .wait_closed ()
108
+ await server1 .wait_closed ()
112
109
server2 .close ()
113
- yield from server2 .wait_closed ()
110
+ await server2 .wait_closed ()
114
111
server3 .close ()
115
- yield from server3 .wait_closed ()
112
+ await server3 .wait_closed ()
116
113
117
114
118
115
def test_unused_port_factory_duplicate (unused_tcp_port_factory , monkeypatch ):
@@ -139,9 +136,9 @@ class Test:
139
136
"""Test that asyncio marked functions work in test methods."""
140
137
141
138
@pytest .mark .asyncio
142
- def test_asyncio_marker_method (self , event_loop ):
139
+ async def test_asyncio_marker_method (self , event_loop ):
143
140
"""Test the asyncio pytest marker in a Test class."""
144
- ret = yield from async_coro (event_loop )
141
+ ret = await async_coro (event_loop )
145
142
assert ret == 'ok'
146
143
147
144
@@ -154,7 +151,7 @@ def remove_loop(self):
154
151
asyncio .set_event_loop (old_loop )
155
152
156
153
@pytest .mark .asyncio
157
- def test_asyncio_marker_without_loop (self , remove_loop ):
154
+ async def test_asyncio_marker_without_loop (self , remove_loop ):
158
155
"""Test the asyncio pytest marker in a Test class."""
159
- ret = yield from async_coro ()
156
+ ret = await async_coro ()
160
157
assert ret == 'ok'
0 commit comments