Skip to content

Commit 0af86f3

Browse files
committed
Stop using pytest-asyncio
It imports us!
1 parent a969e95 commit 0af86f3

File tree

4 files changed

+25
-33
lines changed

4 files changed

+25
-33
lines changed

async_generator/_tests/conftest.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
from functools import wraps, partial
3+
import inspect
4+
5+
6+
# Wrap any 'async def' tests so that they get automatically iterated.
7+
# We used to use pytest-asyncio as a convenient way to do this, but nowadays
8+
# pytest-asyncio uses us! In addition to it being generally bad for our test
9+
# infrastructure to depend on the code-under-test, this totally messes up
10+
# coverage info because depending on pytest's plugin load order, we might get
11+
# imported before pytest-cov can be loaded and start gathering coverage.
12+
@pytest.hookimpl(tryfirst=True)
13+
def pytest_pyfunc_call(pyfuncitem):
14+
if inspect.iscoroutinefunction(pyfuncitem.obj):
15+
fn = pyfuncitem.obj
16+
17+
@wraps(fn)
18+
def wrapper(**kwargs):
19+
coro = fn(**kwargs)
20+
try:
21+
coro.send(None)
22+
except StopIteration:
23+
pass
24+
25+
pyfuncitem.obj = wrapper

async_generator/_tests/test_async_generator.py

-24
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ async def async_multiplied(self, ait):
5555
await yield_(value * self._factor)
5656

5757

58-
@pytest.mark.asyncio
5958
async def test_async_generator():
6059
assert await collect(async_range(10)) == list(range(10))
6160
assert (await collect(double(async_range(5))) == [0, 2, 4, 6, 8])
@@ -72,7 +71,6 @@ async def agen_yield_no_arg():
7271
await yield_()
7372

7473

75-
@pytest.mark.asyncio
7674
async def test_yield_no_arg():
7775
assert await collect(agen_yield_no_arg()) == [None]
7876

@@ -91,7 +89,6 @@ async def async_gen_with_non_None_return():
9189
return "hi"
9290

9391

94-
@pytest.mark.asyncio
9592
async def test_bad_return_value():
9693
gen = async_gen_with_non_None_return()
9794
async for item in gen: # pragma: no branch
@@ -181,7 +178,6 @@ def test_yield_different_entries():
181178
assert yielded == [1, 2, 3, 4]
182179

183180

184-
@pytest.mark.asyncio
185181
async def test_reentrance_forbidden():
186182
@async_generator
187183
async def recurse():
@@ -195,7 +191,6 @@ async def recurse():
195191

196192

197193
# https://bugs.python.org/issue32526
198-
@pytest.mark.asyncio
199194
async def test_reentrance_forbidden_while_suspended_in_coroutine_runner():
200195
@async_generator
201196
async def f():
@@ -226,7 +221,6 @@ async def asend_me():
226221
assert (await yield_(3)) == 4
227222

228223

229-
@pytest.mark.asyncio
230224
async def test_asend():
231225
aiter = asend_me()
232226
assert (await aiter.__anext__()) == 1
@@ -251,7 +245,6 @@ async def athrow_me():
251245
await yield_(3)
252246

253247

254-
@pytest.mark.asyncio
255248
async def test_athrow():
256249
aiter = athrow_me()
257250
assert (await aiter.__anext__()) == 1
@@ -279,7 +272,6 @@ async def close_me_aiter(track):
279272
track[0] = "wtf"
280273

281274

282-
@pytest.mark.asyncio
283275
async def test_aclose():
284276
track = [None]
285277
aiter = close_me_aiter(track)
@@ -291,15 +283,13 @@ async def test_aclose():
291283
assert track[0] == "closed"
292284

293285

294-
@pytest.mark.asyncio
295286
async def test_aclose_on_unstarted_generator():
296287
aiter = close_me_aiter([None])
297288
await aiter.aclose()
298289
async for obj in aiter:
299290
assert False # pragma: no cover
300291

301292

302-
@pytest.mark.asyncio
303293
async def test_aclose_on_finished_generator():
304294
aiter = async_range(3)
305295
async for obj in aiter:
@@ -323,7 +313,6 @@ async def async_yield_during_aclose():
323313
await yield_(2)
324314

325315

326-
@pytest.mark.asyncio
327316
async def test_aclose_yielding():
328317
aiter = sync_yield_during_aclose()
329318
assert (await aiter.__anext__()) == 1
@@ -368,7 +357,6 @@ async def native_async_range(count):
368357
)
369358

370359

371-
@pytest.mark.asyncio
372360
async def test_async_yield_from_():
373361
assert await collect(async_range_twice(3)) == [
374362
0,
@@ -406,7 +394,6 @@ async def wraps_doubles_sends(value):
406394
await yield_from_(doubles_sends(value))
407395

408396

409-
@pytest.mark.asyncio
410397
async def test_async_yield_from_asend():
411398
gen = wraps_doubles_sends(10)
412399
await gen.__anext__() == 20
@@ -416,7 +403,6 @@ async def test_async_yield_from_asend():
416403
await gen.aclose()
417404

418405

419-
@pytest.mark.asyncio
420406
async def test_async_yield_from_athrow():
421407
gen = async_range_twice(2)
422408
assert (await gen.__anext__()) == 0
@@ -435,13 +421,11 @@ async def yields_from_returns_1():
435421
await yield_(await yield_from_(returns_1()))
436422

437423

438-
@pytest.mark.asyncio
439424
async def test_async_yield_from_return_value():
440425
assert await collect(yields_from_returns_1()) == [0, 1]
441426

442427

443428
# Special cases to get coverage
444-
@pytest.mark.asyncio
445429
async def test_yield_from_empty():
446430
@async_generator
447431
async def empty():
@@ -454,7 +438,6 @@ async def yield_from_empty():
454438
assert await collect(yield_from_empty()) == []
455439

456440

457-
@pytest.mark.asyncio
458441
async def test_yield_from_non_generator():
459442
class Countdown:
460443
def __init__(self, count):
@@ -524,7 +507,6 @@ async def yield_from_countdown(count, happenings):
524507
assert h == ["countdown closed", "raise"]
525508

526509

527-
@pytest.mark.asyncio
528510
async def test_yield_from_non_generator_with_no_aclose():
529511
class Countdown:
530512
def __init__(self, count):
@@ -559,7 +541,6 @@ async def yield_from_countdown(count):
559541
await agen.aclose()
560542

561543

562-
@pytest.mark.asyncio
563544
async def test_yield_from_with_old_style_aiter():
564545
# old-style 'async def __aiter__' should still work even on newer pythons
565546
class Countdown:
@@ -584,7 +565,6 @@ async def yield_from_countdown(count):
584565
assert await collect(yield_from_countdown(3)) == [2, 1, 0]
585566

586567

587-
@pytest.mark.asyncio
588568
async def test_yield_from_athrow_raises_StopAsyncIteration():
589569
@async_generator
590570
async def catch():
@@ -615,7 +595,6 @@ async def yield_from_catch():
615595
################################################################
616596

617597

618-
@pytest.mark.asyncio
619598
async def test___del__():
620599
gen = async_range(10)
621600
# Hasn't started yet, so no problem
@@ -699,7 +678,6 @@ def test_collections_abc_AsyncGenerator():
699678
assert isinstance(async_range(10), collections.abc.AsyncGenerator)
700679

701680

702-
@pytest.mark.asyncio
703681
async def test_ag_attributes():
704682
@async_generator
705683
async def f():
@@ -767,7 +745,6 @@ async def lets_exception_out():
767745
await yield_()
768746

769747

770-
@pytest.mark.asyncio
771748
async def test_throw_StopIteration_or_StopAsyncIteration():
772749
for cls in [StopIteration, StopAsyncIteration]:
773750
agen = lets_exception_out()
@@ -781,7 +758,6 @@ async def test_throw_StopIteration_or_StopAsyncIteration():
781758

782759
# No "coroutine was never awaited" warnings for async generators that are not
783760
# iterated
784-
@pytest.mark.asyncio
785761
async def test_no_spurious_unawaited_coroutine_warning(recwarn):
786762
agen = async_range(10)
787763
del agen

async_generator/_tests/test_util.py

-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ async def async_range(count, closed_slot):
1212
closed_slot[0] = True
1313

1414

15-
@pytest.mark.asyncio
1615
async def test_aclosing():
1716
closed_slot = [False]
1817
async with aclosing(async_range(10, closed_slot)) as gen:
@@ -36,7 +35,6 @@ async def test_aclosing():
3635
assert closed_slot[0]
3736

3837

39-
@pytest.mark.asyncio
4038
async def test_contextmanager_do_not_unchain_non_stopiteration_exceptions():
4139
@asynccontextmanager
4240
@async_generator
@@ -100,7 +98,6 @@ async def manager_issue29692_2():
10098
not nativeasyncgenerators,
10199
reason="Python < 3.6 doesn't have native async generators"
102100
)
103-
@pytest.mark.asyncio
104101
async def test_native_contextmanager_do_not_unchain_non_stopiteration_exceptions(
105102
):
106103

@@ -118,7 +115,6 @@ async def test_native_contextmanager_do_not_unchain_non_stopiteration_exceptions
118115
assert excinfo.value.__cause__ is None
119116

120117

121-
@pytest.mark.asyncio
122118
async def test_asynccontextmanager_exception_passthrough():
123119
# This was the cause of annoying coverage flapping, see gh-140
124120
@asynccontextmanager
@@ -132,7 +128,6 @@ async def noop_async_context_manager():
132128
raise exc_type
133129

134130

135-
@pytest.mark.asyncio
136131
async def test_asynccontextmanager_catches_exception():
137132
@asynccontextmanager
138133
@async_generator
@@ -144,7 +139,6 @@ async def catch_it():
144139
raise ValueError
145140

146141

147-
@pytest.mark.asyncio
148142
async def test_asynccontextmanager_no_yield():
149143
@asynccontextmanager
150144
@async_generator
@@ -158,7 +152,6 @@ async def yeehaw():
158152
assert "didn't yield" in str(excinfo.value)
159153

160154

161-
@pytest.mark.asyncio
162155
async def test_asynccontextmanager_too_many_yields():
163156
@asynccontextmanager
164157
@async_generator
@@ -182,7 +175,6 @@ async def doubleyield():
182175
assert "didn't stop after athrow" in str(excinfo.value)
183176

184177

185-
@pytest.mark.asyncio
186178
async def test_asynccontextmanager_requires_asyncgenfunction():
187179
with pytest.raises(TypeError):
188180

test-requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
pytest
22
pytest-cov
3-
pytest-asyncio

0 commit comments

Comments
 (0)