11"""Quick'n'dirty unit tests for provided fixtures and markers."""
22import asyncio
3- import os
43import pytest
54
65import pytest_asyncio .plugin
76
87
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 )
1210 return 'ok'
1311
1412
1513def test_event_loop_fixture (event_loop ):
1614 """Test the injection of the event_loop fixture."""
1715 assert event_loop
18- ret = event_loop .run_until_complete (async_coro (event_loop ))
16+ ret = event_loop .run_until_complete (async_coro ())
1917 assert ret == 'ok'
2018
2119
2220@pytest .mark .asyncio
23- def test_asyncio_marker ():
21+ async def test_asyncio_marker ():
2422 """Test the asyncio pytest marker."""
25- yield # sleep(0)
23+ await asyncio . sleep (0 )
2624
2725
2826@pytest .mark .xfail (reason = 'need a failure' , strict = True )
@@ -45,13 +43,11 @@ async def closer(_, writer):
4543 writer .close ()
4644
4745 server1 = await asyncio .start_server (closer , host = 'localhost' ,
48- port = unused_tcp_port ,
49- loop = event_loop )
46+ port = unused_tcp_port )
5047
5148 with pytest .raises (IOError ):
5249 await asyncio .start_server (closer , host = 'localhost' ,
53- port = unused_tcp_port ,
54- loop = event_loop )
50+ port = unused_tcp_port )
5551
5652 server1 .close ()
5753 await server1 .wait_closed ()
@@ -68,20 +64,16 @@ async def closer(_, writer):
6864 unused_tcp_port_factory ())
6965
7066 server1 = await asyncio .start_server (closer , host = 'localhost' ,
71- port = port1 ,
72- loop = event_loop )
67+ port = port1 )
7368 server2 = await asyncio .start_server (closer , host = 'localhost' ,
74- port = port2 ,
75- loop = event_loop )
69+ port = port2 )
7670 server3 = await asyncio .start_server (closer , host = 'localhost' ,
77- port = port3 ,
78- loop = event_loop )
71+ port = port3 )
7972
8073 for port in port1 , port2 , port3 :
8174 with pytest .raises (IOError ):
8275 await asyncio .start_server (closer , host = 'localhost' ,
83- port = port ,
84- loop = event_loop )
76+ port = port )
8577
8678 server1 .close ()
8779 await server1 .wait_closed ()
@@ -117,7 +109,7 @@ class Test:
117109 @pytest .mark .asyncio
118110 async def test_asyncio_marker_method (self , event_loop ):
119111 """Test the asyncio pytest marker in a Test class."""
120- ret = await async_coro (event_loop )
112+ ret = await async_coro ()
121113 assert ret == 'ok'
122114
123115
0 commit comments