Skip to content

Commit 4c2a82f

Browse files
committed
Drop dependency on async_generator
1 parent 66188cb commit 4c2a82f

9 files changed

+43
-138
lines changed

docs-requirements.in

-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ towncrier != 19.9.0,!= 21.3.0
1010

1111
# pytest-trio's own dependencies
1212
trio >= 0.22.0
13-
async_generator >= 1.9
1413
outcome >= 1.1.0
1514
pytest >= 7.2.0

docs-requirements.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
alabaster==0.7.12
88
# via sphinx
99
async-generator==1.10
10-
# via
11-
# -r docs-requirements.in
12-
# trio
10+
# via trio
1311
attrs==22.1.0
1412
# via
1513
# -r docs-requirements.in

docs/source/quickstart.rst

-18
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,6 @@ And we're done! Let's try running pytest again:
9393
============================== FAILURES ==============================
9494
__________________________ test_should_fail __________________________
9595
96-
value = <trio.Nursery object at 0x7f97b21fafa0>
97-
98-
async def yield_(value=None):
99-
> return await _yield_(value)
100-
101-
venv/lib/python3.8/site-packages/async_generator/_impl.py:106:
102-
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
103-
venv/lib/python3.8/site-packages/async_generator/_impl.py:99: in _yield_
104-
return (yield _wrap(value))
105-
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
106-
10796
async def test_should_fail():
10897
> assert False
10998
E assert False
@@ -179,13 +168,6 @@ regular pytest fixture::
179168
# Teardown code, executed after the test is done
180169
await connection.execute("ROLLBACK")
181170

182-
If you need to support Python 3.5, which doesn't allow ``yield``
183-
inside an ``async def`` function, then you can define async fixtures
184-
using the `async_generator
185-
<https://async-generator.readthedocs.io/en/latest/reference.html>`__
186-
library - just make sure to put the ``@pytest.fixture`` *above* the
187-
``@async_generator``.
188-
189171

190172
.. _server-fixture-example:
191173

pytest.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
[pytest]
2-
addopts = -W error -ra -v --pyargs pytest_trio --verbose --cov
1+
[pytest]
2+
addopts = -W error -ra -v --pyargs pytest_trio --verbose --cov

pytest_trio/_tests/test_async_yield_fixture.py

+24-78
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,17 @@
1-
import sys
2-
import pytest
3-
import re
4-
5-
6-
@pytest.fixture(params=["Python>=36", "async_generator"])
7-
def async_yield_implementation(request):
8-
if request.param == "Python>=36":
9-
10-
def patch_code(code):
11-
# Convert code to use Python>=3.6 builtin async generator
12-
code = re.sub(r"(?m)^\s*@async_generator\n", r"", code)
13-
code = re.sub(r"await yield_", r"yield", code)
14-
return code
15-
16-
return patch_code
17-
else:
18-
return lambda x: x
19-
20-
21-
def test_single_async_yield_fixture(testdir, async_yield_implementation):
1+
def test_single_async_yield_fixture(testdir):
222
testdir.makepyfile(
23-
async_yield_implementation(
24-
"""
3+
"""
254
import pytest
265
import trio
27-
from async_generator import async_generator, yield_
286
297
events = []
308
319
@pytest.fixture
32-
@async_generator
3310
async def fix1():
3411
events.append('fix1 setup')
3512
await trio.sleep(0)
3613
37-
await yield_('fix1')
14+
yield 'fix1'
3815
3916
await trio.sleep(0)
4017
events.append('fix1 teardown')
@@ -53,43 +30,38 @@ def test_after():
5330
'fix1 teardown',
5431
]
5532
"""
56-
)
5733
)
5834

5935
result = testdir.runpytest()
6036

6137
result.assert_outcomes(passed=3)
6238

6339

64-
def test_nested_async_yield_fixture(testdir, async_yield_implementation):
40+
def test_nested_async_yield_fixture(testdir):
6541

6642
testdir.makepyfile(
67-
async_yield_implementation(
68-
"""
43+
"""
6944
import pytest
7045
import trio
71-
from async_generator import async_generator, yield_
7246
7347
events = []
7448
7549
@pytest.fixture
76-
@async_generator
7750
async def fix2():
7851
events.append('fix2 setup')
7952
await trio.sleep(0)
8053
81-
await yield_('fix2')
54+
yield 'fix2'
8255
8356
await trio.sleep(0)
8457
events.append('fix2 teardown')
8558
8659
@pytest.fixture
87-
@async_generator
8860
async def fix1(fix2):
8961
events.append('fix1 setup')
9062
await trio.sleep(0)
9163
92-
await yield_('fix1')
64+
yield 'fix1'
9365
9466
await trio.sleep(0)
9567
events.append('fix1 teardown')
@@ -113,32 +85,28 @@ def test_after():
11385
'fix2 teardown',
11486
]
11587
"""
116-
)
11788
)
11889

11990
result = testdir.runpytest()
12091

12192
result.assert_outcomes(passed=3)
12293

12394

124-
def test_async_yield_fixture_within_sync_fixture(testdir, async_yield_implementation):
95+
def test_async_yield_fixture_within_sync_fixture(testdir):
12596

12697
testdir.makepyfile(
127-
async_yield_implementation(
128-
"""
98+
"""
12999
import pytest
130100
import trio
131-
from async_generator import async_generator, yield_
132101
133102
events = []
134103
135104
@pytest.fixture
136-
@async_generator
137105
async def fix2():
138106
events.append('fix2 setup')
139107
await trio.sleep(0)
140108
141-
await yield_('fix2')
109+
yield 'fix2'
142110
143111
await trio.sleep(0)
144112
events.append('fix2 teardown')
@@ -163,34 +131,28 @@ def test_after():
163131
'fix2 teardown',
164132
]
165133
"""
166-
)
167134
)
168135

169136
result = testdir.runpytest()
170137

171138
result.assert_outcomes(passed=3)
172139

173140

174-
def test_async_yield_fixture_within_sync_yield_fixture(
175-
testdir, async_yield_implementation
176-
):
141+
def test_async_yield_fixture_within_sync_yield_fixture(testdir):
177142

178143
testdir.makepyfile(
179-
async_yield_implementation(
180-
"""
144+
"""
181145
import pytest
182146
import trio
183-
from async_generator import async_generator, yield_
184147
185148
events = []
186149
187150
@pytest.fixture
188-
@async_generator
189151
async def fix2():
190152
events.append('fix2 setup')
191153
await trio.sleep(0)
192154
193-
await yield_('fix2')
155+
yield 'fix2'
194156
195157
await trio.sleep(0)
196158
events.append('fix2 teardown')
@@ -220,36 +182,31 @@ def test_after():
220182
'fix2 teardown',
221183
]
222184
"""
223-
)
224185
)
225186

226187
result = testdir.runpytest()
227188

228189
result.assert_outcomes(passed=3)
229190

230191

231-
def test_async_yield_fixture_with_multiple_yields(testdir, async_yield_implementation):
192+
def test_async_yield_fixture_with_multiple_yields(testdir):
232193

233194
testdir.makepyfile(
234-
async_yield_implementation(
235-
"""
195+
"""
236196
import pytest
237197
import trio
238-
from async_generator import async_generator, yield_
239198
240199
@pytest.fixture
241-
@async_generator
242200
async def fix1():
243201
await trio.sleep(0)
244-
await yield_('good')
202+
yield 'good'
245203
await trio.sleep(0)
246-
await yield_('bad')
204+
yield 'bad'
247205
248206
@pytest.mark.trio
249207
async def test_actual_test(fix1):
250208
pass
251209
"""
252-
)
253210
)
254211

255212
result = testdir.runpytest()
@@ -259,14 +216,12 @@ async def test_actual_test(fix1):
259216
result.assert_outcomes(failed=1)
260217

261218

262-
def test_async_yield_fixture_with_nursery(testdir, async_yield_implementation):
219+
def test_async_yield_fixture_with_nursery(testdir):
263220

264221
testdir.makepyfile(
265-
async_yield_implementation(
266-
"""
222+
"""
267223
import pytest
268224
import trio
269-
from async_generator import async_generator, yield_
270225
271226
272227
async def handle_client(stream):
@@ -276,11 +231,10 @@ async def handle_client(stream):
276231
277232
278233
@pytest.fixture
279-
@async_generator
280234
async def server():
281235
async with trio.open_nursery() as nursery:
282236
listeners = await nursery.start(trio.serve_tcp, handle_client, 0)
283-
await yield_(listeners[0])
237+
yield listeners[0]
284238
nursery.cancel_scope.cancel()
285239
286240
@@ -291,42 +245,35 @@ async def test_actual_test(server):
291245
rep = await stream.receive_some(4)
292246
assert rep == b'ping'
293247
"""
294-
)
295248
)
296249

297250
result = testdir.runpytest()
298251

299252
result.assert_outcomes(passed=1)
300253

301254

302-
def test_async_yield_fixture_crashed_teardown_allow_other_teardowns(
303-
testdir, async_yield_implementation
304-
):
255+
def test_async_yield_fixture_crashed_teardown_allow_other_teardowns(testdir):
305256

306257
testdir.makepyfile(
307-
async_yield_implementation(
308-
"""
258+
"""
309259
import pytest
310260
import trio
311-
from async_generator import async_generator, yield_
312261
313262
setup_events = set()
314263
teardown_events = set()
315264
316265
@pytest.fixture
317-
@async_generator
318266
async def good_fixture():
319267
async with trio.open_nursery() as nursery:
320268
setup_events.add('good_fixture setup')
321-
await yield_(None)
269+
yield None
322270
teardown_events.add('good_fixture teardown')
323271
324272
@pytest.fixture
325-
@async_generator
326273
async def bad_fixture():
327274
async with trio.open_nursery() as nursery:
328275
setup_events.add('bad_fixture setup')
329-
await yield_(None)
276+
yield None
330277
teardown_events.add('bad_fixture teardown')
331278
raise RuntimeError('Crash during fixture teardown')
332279
@@ -348,7 +295,6 @@ def test_after():
348295
'good_fixture teardown',
349296
}
350297
"""
351-
)
352298
)
353299

354300
result = testdir.runpytest()

pytest_trio/_tests/test_fixture_mistakes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,12 @@ def test_fixture_cancels_test_but_doesnt_raise(testdir, enable_trio_mode):
123123
"""
124124
import pytest
125125
import trio
126-
from async_generator import async_generator, yield_
127126
128127
@pytest.fixture
129-
@async_generator
130128
async def async_fixture():
131129
with trio.CancelScope() as cscope:
132130
cscope.cancel()
133-
await yield_()
131+
yield
134132
135133
136134
async def test_whatever(async_fixture):
@@ -164,4 +162,6 @@ async def test_whatever(mock_clock, extra_clock):
164162
result = testdir.runpytest()
165163

166164
result.assert_outcomes(failed=1)
167-
result.stdout.fnmatch_lines(["*ValueError: too many clocks spoil the broth!*"])
165+
result.stdout.fnmatch_lines(
166+
["*ValueError: Expected at most one Clock in kwargs, got *"]
167+
)

0 commit comments

Comments
 (0)