@@ -131,7 +131,11 @@ async def test_create_pool_deprecations(mysql_params, loop):
131131            warnings .simplefilter ("always" )
132132            async  with  pool .get () as  conn :
133133                pass 
134-     assert  issubclass (w [- 1 ].category , DeprecationWarning )
134+     # The first warning emitted is expected to be DeprecationWarning: 
135+     # in the past, we used to check for the last one but this assumption 
136+     # breaks under Python 3.7 that also emits a `ResourceWarning` when 
137+     # executed with `PYTHONASYNCIODEBUG=1`. 
138+     assert  issubclass (w [0 ].category , DeprecationWarning )
135139    assert  conn .closed 
136140
137141    async  with  create_pool (loop = loop , ** mysql_params ) as  pool :
@@ -149,9 +153,10 @@ async def test_sa_connection(table, mysql_params, loop):
149153        connection  =  await  engine .acquire ()
150154        assert  not  connection .closed 
151155        async  with  connection :
152-             ret  =  []
153-             async  for  i  in  connection .execute (tbl .select ()):
154-                 ret .append (i )
156+             async  with  connection .execute (tbl .select ()) as  cursor :
157+                 ret  =  []
158+                 async  for  i  in  cursor :
159+                     ret .append (i )
155160            assert  [(1 , 'a' ), (2 , 'b' ), (3 , 'c' )] ==  ret 
156161        assert  connection .closed 
157162
@@ -194,21 +199,23 @@ async def test_sa_transaction_rollback(loop, mysql_params, table):
194199async  def  test_create_engine (loop , mysql_params , table ):
195200    async  with  sa .create_engine (loop = loop , ** mysql_params ) as  engine :
196201        async  with  engine .acquire () as  conn :
197-             ret  =  []
198-             async  for  i  in  conn .execute (tbl .select ()):
199-                 ret .append (i )
200-             assert  [(1 , 'a' ), (2 , 'b' ), (3 , 'c' )] ==  ret 
202+             async  with  conn .execute (tbl .select ()) as  cursor :
203+                 ret  =  []
204+                 async  for  i  in  cursor :
205+                     ret .append (i )
206+                 assert  [(1 , 'a' ), (2 , 'b' ), (3 , 'c' )] ==  ret 
201207
202208
203209@pytest .mark .run_loop  
204210async  def  test_engine (loop , mysql_params , table ):
205211    engine  =  await  sa .create_engine (loop = loop , ** mysql_params )
206212    async  with  engine :
207213        async  with  engine .acquire () as  conn :
208-             ret  =  []
209-             async  for  i  in  conn .execute (tbl .select ()):
210-                 ret .append (i )
211-             assert  [(1 , 'a' ), (2 , 'b' ), (3 , 'c' )] ==  ret 
214+             async  with  conn .execute (tbl .select ()) as  cursor :
215+                 ret  =  []
216+                 async  for  i  in  cursor :
217+                     ret .append (i )
218+                 assert  [(1 , 'a' ), (2 , 'b' ), (3 , 'c' )] ==  ret 
212219
213220
214221@pytest .mark .run_loop  
@@ -218,7 +225,7 @@ async def test_transaction_context_manager(loop, mysql_params, table):
218225            async  with  conn .begin () as  tr :
219226                async  with  conn .execute (tbl .select ()) as  cursor :
220227                    ret  =  []
221-                     async  for  i  in  conn . execute ( tbl . select ()) :
228+                     async  for  i  in  cursor :
222229                        ret .append (i )
223230                    assert  [(1 , 'a' ), (2 , 'b' ), (3 , 'c' )] ==  ret 
224231                assert  cursor .closed 
0 commit comments