Skip to content

Commit e4cba8f

Browse files
committed
Support python 3.7 and 3.8 in tests and travis CI
Some changes in tests were needed to make them pass: - `issubclass(w[0].category, DeprecationWarning)` - previous version breaks on python 3.7 executed with PYTHONASYNCIODEBUG=1 - `disable_gc` fixture - I can only suspect that in p3.7 and p3.8 the connection object was automatically garbage collected before the `gc.collect()` was invoked. - curosor `async for` usage was incorrect
1 parent f9b86aa commit e4cba8f

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ language: python
22

33
python:
44
- 3.6
5+
- 3.7
6+
- 3.8
57

68
env:
79
matrix:

tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222
uvloop = None
2323

2424

25+
@pytest.fixture
26+
def disable_gc():
27+
gc_enabled = gc.isenabled()
28+
if gc_enabled:
29+
gc.disable()
30+
gc.collect()
31+
yield
32+
if gc_enabled:
33+
gc.collect()
34+
gc.enable()
35+
36+
2537
@pytest.fixture(scope='session')
2638
def unused_port():
2739
def f():

tests/test_async_with.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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):
194199
async 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
204210
async 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

tests/test_connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ async def test_connection_double_ensure_closed(connection_creator):
219219

220220

221221
@pytest.mark.run_loop
222+
@pytest.mark.usefixtures("disable_gc")
222223
async def test___del__(connection_creator):
223224
conn = await connection_creator()
224225
with pytest.warns(ResourceWarning):

0 commit comments

Comments
 (0)