@@ -131,7 +131,11 @@ async def test_create_pool_deprecations(mysql_params, loop):
131
131
warnings .simplefilter ("always" )
132
132
async with pool .get () as conn :
133
133
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 )
135
139
assert conn .closed
136
140
137
141
async with create_pool (loop = loop , ** mysql_params ) as pool :
@@ -149,9 +153,10 @@ async def test_sa_connection(table, mysql_params, loop):
149
153
connection = await engine .acquire ()
150
154
assert not connection .closed
151
155
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 )
155
160
assert [(1 , 'a' ), (2 , 'b' ), (3 , 'c' )] == ret
156
161
assert connection .closed
157
162
@@ -194,21 +199,23 @@ async def test_sa_transaction_rollback(loop, mysql_params, table):
194
199
async def test_create_engine (loop , mysql_params , table ):
195
200
async with sa .create_engine (loop = loop , ** mysql_params ) as engine :
196
201
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
201
207
202
208
203
209
@pytest .mark .run_loop
204
210
async def test_engine (loop , mysql_params , table ):
205
211
engine = await sa .create_engine (loop = loop , ** mysql_params )
206
212
async with engine :
207
213
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
212
219
213
220
214
221
@pytest .mark .run_loop
@@ -218,7 +225,7 @@ async def test_transaction_context_manager(loop, mysql_params, table):
218
225
async with conn .begin () as tr :
219
226
async with conn .execute (tbl .select ()) as cursor :
220
227
ret = []
221
- async for i in conn . execute ( tbl . select ()) :
228
+ async for i in cursor :
222
229
ret .append (i )
223
230
assert [(1 , 'a' ), (2 , 'b' ), (3 , 'c' )] == ret
224
231
assert cursor .closed
0 commit comments