1
1
"""Quick'n'dirty unit tests for provided fixtures and markers."""
2
2
import asyncio
3
- import pytest
4
3
4
+ import pytest
5
5
import pytest_asyncio .plugin
6
6
7
7
8
8
async def async_coro ():
9
9
await asyncio .sleep (0 )
10
- return 'ok'
10
+ return "ok"
11
11
12
12
13
13
def test_event_loop_fixture (event_loop ):
14
14
"""Test the injection of the event_loop fixture."""
15
15
assert event_loop
16
16
ret = event_loop .run_until_complete (async_coro ())
17
- assert ret == 'ok'
17
+ assert ret == "ok"
18
18
19
19
20
20
@pytest .mark .asyncio
@@ -23,7 +23,7 @@ async def test_asyncio_marker():
23
23
await asyncio .sleep (0 )
24
24
25
25
26
- @pytest .mark .xfail (reason = ' need a failure' , strict = True )
26
+ @pytest .mark .xfail (reason = " need a failure" , strict = True )
27
27
@pytest .mark .asyncio
28
28
def test_asyncio_marker_fail ():
29
29
assert False
@@ -42,12 +42,10 @@ async def test_unused_port_fixture(unused_tcp_port, event_loop):
42
42
async def closer (_ , writer ):
43
43
writer .close ()
44
44
45
- server1 = await asyncio .start_server (closer , host = 'localhost' ,
46
- port = unused_tcp_port )
45
+ server1 = await asyncio .start_server (closer , host = "localhost" , port = unused_tcp_port )
47
46
48
47
with pytest .raises (IOError ):
49
- await asyncio .start_server (closer , host = 'localhost' ,
50
- port = unused_tcp_port )
48
+ await asyncio .start_server (closer , host = "localhost" , port = unused_tcp_port )
51
49
52
50
server1 .close ()
53
51
await server1 .wait_closed ()
@@ -60,20 +58,19 @@ async def test_unused_port_factory_fixture(unused_tcp_port_factory, event_loop):
60
58
async def closer (_ , writer ):
61
59
writer .close ()
62
60
63
- port1 , port2 , port3 = (unused_tcp_port_factory (), unused_tcp_port_factory (),
64
- unused_tcp_port_factory ())
61
+ port1 , port2 , port3 = (
62
+ unused_tcp_port_factory (),
63
+ unused_tcp_port_factory (),
64
+ unused_tcp_port_factory (),
65
+ )
65
66
66
- server1 = await asyncio .start_server (closer , host = 'localhost' ,
67
- port = port1 )
68
- server2 = await asyncio .start_server (closer , host = 'localhost' ,
69
- port = port2 )
70
- server3 = await asyncio .start_server (closer , host = 'localhost' ,
71
- port = port3 )
67
+ server1 = await asyncio .start_server (closer , host = "localhost" , port = port1 )
68
+ server2 = await asyncio .start_server (closer , host = "localhost" , port = port2 )
69
+ server3 = await asyncio .start_server (closer , host = "localhost" , port = port3 )
72
70
73
71
for port in port1 , port2 , port3 :
74
72
with pytest .raises (IOError ):
75
- await asyncio .start_server (closer , host = 'localhost' ,
76
- port = port )
73
+ await asyncio .start_server (closer , host = "localhost" , port = port )
77
74
78
75
server1 .close ()
79
76
await server1 .wait_closed ()
@@ -96,8 +93,7 @@ def mock_unused_tcp_port():
96
93
else :
97
94
return 10000 + counter
98
95
99
- monkeypatch .setattr (pytest_asyncio .plugin , '_unused_tcp_port' ,
100
- mock_unused_tcp_port )
96
+ monkeypatch .setattr (pytest_asyncio .plugin , "_unused_tcp_port" , mock_unused_tcp_port )
101
97
102
98
assert unused_tcp_port_factory () == 10000
103
99
assert unused_tcp_port_factory () > 10000
@@ -110,7 +106,7 @@ class Test:
110
106
async def test_asyncio_marker_method (self , event_loop ):
111
107
"""Test the asyncio pytest marker in a Test class."""
112
108
ret = await async_coro ()
113
- assert ret == 'ok'
109
+ assert ret == "ok"
114
110
115
111
116
112
class TestUnexistingLoop :
@@ -125,7 +121,7 @@ def remove_loop(self):
125
121
async def test_asyncio_marker_without_loop (self , remove_loop ):
126
122
"""Test the asyncio pytest marker in a Test class."""
127
123
ret = await async_coro ()
128
- assert ret == 'ok'
124
+ assert ret == "ok"
129
125
130
126
131
127
class TestEventLoopStartedBeforeFixtures :
@@ -150,12 +146,11 @@ async def test_event_loop_before_fixture(self, event_loop, loop):
150
146
assert await loop .run_in_executor (None , self .foo ) == 1
151
147
152
148
153
-
154
149
@pytest .mark .asyncio
155
150
async def test_no_warning_on_skip ():
156
151
pytest .skip ("Test a skip error inside asyncio" )
157
152
158
153
159
154
def test_async_close_loop (event_loop ):
160
155
event_loop .close ()
161
- return 'ok'
156
+ return "ok"
0 commit comments