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
@@ -20,20 +19,6 @@ def test_event_loop_fixture(event_loop):
20
19
assert ret == 'ok'
21
20
22
21
23
- def test_event_loop_processpool_fixture (event_loop_process_pool ):
24
- """Test the injection of the event_loop with a process pool fixture."""
25
- assert event_loop_process_pool
26
-
27
- ret = event_loop_process_pool .run_until_complete (
28
- async_coro (event_loop_process_pool ))
29
- assert ret == 'ok'
30
-
31
- this_pid = os .getpid ()
32
- future = event_loop_process_pool .run_in_executor (None , os .getpid )
33
- pool_pid = event_loop_process_pool .run_until_complete (future )
34
- assert this_pid != pool_pid
35
-
36
-
37
22
@pytest .mark .asyncio
38
23
def test_asyncio_marker ():
39
24
"""Test the asyncio pytest marker."""
@@ -52,67 +37,58 @@ def test_asyncio_marker_with_default_param(a_param=None):
52
37
yield # sleep(0)
53
38
54
39
55
- @pytest .mark .asyncio_process_pool
56
- def test_asyncio_process_pool_marker (event_loop ):
57
- """Test the asyncio pytest marker."""
58
- ret = yield from async_coro (event_loop )
59
- assert ret == 'ok'
60
-
61
-
62
40
@pytest .mark .asyncio
63
- def test_unused_port_fixture (unused_tcp_port , event_loop ):
41
+ async def test_unused_port_fixture (unused_tcp_port , event_loop ):
64
42
"""Test the unused TCP port fixture."""
65
43
66
- @asyncio .coroutine
67
- def closer (_ , writer ):
44
+ async def closer (_ , writer ):
68
45
writer .close ()
69
46
70
- server1 = yield from asyncio .start_server (closer , host = 'localhost' ,
71
- port = unused_tcp_port ,
72
- loop = event_loop )
47
+ server1 = await asyncio .start_server (closer , host = 'localhost' ,
48
+ port = unused_tcp_port ,
49
+ loop = event_loop )
73
50
74
51
with pytest .raises (IOError ):
75
- yield from asyncio .start_server (closer , host = 'localhost' ,
76
- port = unused_tcp_port ,
77
- loop = event_loop )
52
+ await asyncio .start_server (closer , host = 'localhost' ,
53
+ port = unused_tcp_port ,
54
+ loop = event_loop )
78
55
79
56
server1 .close ()
80
- yield from server1 .wait_closed ()
57
+ await server1 .wait_closed ()
81
58
82
59
83
60
@pytest .mark .asyncio
84
- def test_unused_port_factory_fixture (unused_tcp_port_factory , event_loop ):
61
+ async def test_unused_port_factory_fixture (unused_tcp_port_factory , event_loop ):
85
62
"""Test the unused TCP port factory fixture."""
86
63
87
- @asyncio .coroutine
88
- def closer (_ , writer ):
64
+ async def closer (_ , writer ):
89
65
writer .close ()
90
66
91
67
port1 , port2 , port3 = (unused_tcp_port_factory (), unused_tcp_port_factory (),
92
68
unused_tcp_port_factory ())
93
69
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 )
70
+ server1 = await asyncio .start_server (closer , host = 'localhost' ,
71
+ port = port1 ,
72
+ loop = event_loop )
73
+ server2 = await asyncio .start_server (closer , host = 'localhost' ,
74
+ port = port2 ,
75
+ loop = event_loop )
76
+ server3 = await asyncio .start_server (closer , host = 'localhost' ,
77
+ port = port3 ,
78
+ loop = event_loop )
103
79
104
80
for port in port1 , port2 , port3 :
105
81
with pytest .raises (IOError ):
106
- yield from asyncio .start_server (closer , host = 'localhost' ,
107
- port = port ,
108
- loop = event_loop )
82
+ await asyncio .start_server (closer , host = 'localhost' ,
83
+ port = port ,
84
+ loop = event_loop )
109
85
110
86
server1 .close ()
111
- yield from server1 .wait_closed ()
87
+ await server1 .wait_closed ()
112
88
server2 .close ()
113
- yield from server2 .wait_closed ()
89
+ await server2 .wait_closed ()
114
90
server3 .close ()
115
- yield from server3 .wait_closed ()
91
+ await server3 .wait_closed ()
116
92
117
93
118
94
def test_unused_port_factory_duplicate (unused_tcp_port_factory , monkeypatch ):
@@ -139,9 +115,9 @@ class Test:
139
115
"""Test that asyncio marked functions work in test methods."""
140
116
141
117
@pytest .mark .asyncio
142
- def test_asyncio_marker_method (self , event_loop ):
118
+ async def test_asyncio_marker_method (self , event_loop ):
143
119
"""Test the asyncio pytest marker in a Test class."""
144
- ret = yield from async_coro (event_loop )
120
+ ret = await async_coro (event_loop )
145
121
assert ret == 'ok'
146
122
147
123
@@ -154,7 +130,7 @@ def remove_loop(self):
154
130
asyncio .set_event_loop (old_loop )
155
131
156
132
@pytest .mark .asyncio
157
- def test_asyncio_marker_without_loop (self , remove_loop ):
133
+ async def test_asyncio_marker_without_loop (self , remove_loop ):
158
134
"""Test the asyncio pytest marker in a Test class."""
159
- ret = yield from async_coro ()
135
+ ret = await async_coro ()
160
136
assert ret == 'ok'
0 commit comments