1
1
"""Quick'n'dirty unit tests for provided fixtures and markers."""
2
2
import asyncio
3
- import os
4
3
import pytest
5
4
6
5
import pytest_asyncio .plugin
7
6
8
7
9
- async def async_coro (loop = None ):
10
- """A very simple coroutine."""
11
- await asyncio .sleep (0 , loop = loop )
8
+ async def async_coro ():
9
+ await asyncio .sleep (0 )
12
10
return 'ok'
13
11
14
12
15
13
def test_event_loop_fixture (event_loop ):
16
14
"""Test the injection of the event_loop fixture."""
17
15
assert event_loop
18
- ret = event_loop .run_until_complete (async_coro (event_loop ))
16
+ ret = event_loop .run_until_complete (async_coro ())
19
17
assert ret == 'ok'
20
18
21
19
22
20
@pytest .mark .asyncio
23
- def test_asyncio_marker ():
21
+ async def test_asyncio_marker ():
24
22
"""Test the asyncio pytest marker."""
25
- yield # sleep(0)
23
+ await asyncio . sleep (0 )
26
24
27
25
28
26
@pytest .mark .xfail (reason = 'need a failure' , strict = True )
@@ -45,13 +43,11 @@ async def closer(_, writer):
45
43
writer .close ()
46
44
47
45
server1 = await asyncio .start_server (closer , host = 'localhost' ,
48
- port = unused_tcp_port ,
49
- loop = event_loop )
46
+ port = unused_tcp_port )
50
47
51
48
with pytest .raises (IOError ):
52
49
await asyncio .start_server (closer , host = 'localhost' ,
53
- port = unused_tcp_port ,
54
- loop = event_loop )
50
+ port = unused_tcp_port )
55
51
56
52
server1 .close ()
57
53
await server1 .wait_closed ()
@@ -68,20 +64,16 @@ async def closer(_, writer):
68
64
unused_tcp_port_factory ())
69
65
70
66
server1 = await asyncio .start_server (closer , host = 'localhost' ,
71
- port = port1 ,
72
- loop = event_loop )
67
+ port = port1 )
73
68
server2 = await asyncio .start_server (closer , host = 'localhost' ,
74
- port = port2 ,
75
- loop = event_loop )
69
+ port = port2 )
76
70
server3 = await asyncio .start_server (closer , host = 'localhost' ,
77
- port = port3 ,
78
- loop = event_loop )
71
+ port = port3 )
79
72
80
73
for port in port1 , port2 , port3 :
81
74
with pytest .raises (IOError ):
82
75
await asyncio .start_server (closer , host = 'localhost' ,
83
- port = port ,
84
- loop = event_loop )
76
+ port = port )
85
77
86
78
server1 .close ()
87
79
await server1 .wait_closed ()
@@ -117,7 +109,7 @@ class Test:
117
109
@pytest .mark .asyncio
118
110
async def test_asyncio_marker_method (self , event_loop ):
119
111
"""Test the asyncio pytest marker in a Test class."""
120
- ret = await async_coro (event_loop )
112
+ ret = await async_coro ()
121
113
assert ret == 'ok'
122
114
123
115
0 commit comments