Skip to content

Commit 5a8855e

Browse files
committed
Asynchronous coroutine and generator fixtures x 4.
This commit is the next in a commit chain generalizing the `--beartype-fixtures` option accepted by this plugin to transparently type-check both **asynchronous coroutine fixtures** (i.e., fixtures whose signatures are prefixed by the `async` keyword and whose bodies contain *no* `yield` statements) and **asynchronous generator fixtures** (i.e., fixtures whose signatures are prefixed by the `async` keyword and whose bodies contain one or more `yield` statements), en-route to publishing our upcoming `pytest-beartype 0.3.0` release. Specifically, this commit: * Defines additional fixtures in *all* varieties (i.e., synchronous non-generators, synchronous generators, asynchronous non-generators, and asynchronous generators) validating that this plugin properly handles `@beartype` decoration-time type-checking errors. * Defines all asynchronous unit tests necessary to test the new `--beartype-tests` plugin option with respect to asynchronicity. Sadly, these tests currently induce spurious failures. The culprit is pytest's standard `pytester` plugin, which appears to be incapable of supporting asynchronous operation. Let's do this! Rooooooar! Pretend you felt intimidated. (*Send it to a sander!*)
1 parent 91855dc commit 5a8855e

File tree

6 files changed

+559
-244
lines changed

6 files changed

+559
-244
lines changed

pytest_beartype_test/a90_func/data/_fixture/fixasync.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# Asynchronous non-generator root fixtures requiring *NO* other fixtures.
2222

2323
@fixture
24-
async def fixture_async_nongenerator() -> str:
24+
async def fixture_async_nongen() -> str:
2525
'''
2626
Asynchronous non-generator fixture annotated by a correct return hint.
2727
'''
@@ -31,7 +31,7 @@ async def fixture_async_nongenerator() -> str:
3131

3232

3333
@fixture
34-
async def fixture_async_nongenerator_bad() -> int:
34+
async def fixture_async_nongen_bad() -> int:
3535
'''
3636
Asynchronous non-generator fixture annotated by an incorrect return hint.
3737
'''
@@ -44,26 +44,26 @@ async def fixture_async_nongenerator_bad() -> int:
4444
# fixtures.
4545

4646
@fixture
47-
async def fixture_async_nongenerator_needs_fixture(
48-
fixture_async_nongenerator: str) -> str:
47+
async def fixture_async_nongen_needs_fixture(
48+
fixture_async_nongen: str) -> str:
4949
'''
5050
Asynchronous non-generator fixture requiring another such fixture annotated
5151
by the same parameter hint as the return hint annotating the latter fixture.
5252
'''
5353

5454
# Return an object satisfying the return hint annotating this fixture.
55-
return fixture_async_nongenerator
55+
return fixture_async_nongen
5656

5757

5858
@fixture
59-
async def fixture_async_nongenerator_needs_fixtures_bad(
59+
async def fixture_async_nongen_needs_fixtures_bad(
6060
# Two or more parent fixtures that are *ALL* correctly annotated.
61-
fixture_async_nongenerator: str,
62-
fixture_async_nongenerator_needs_fixture: str,
61+
fixture_async_nongen: str,
62+
fixture_async_nongen_needs_fixture: str,
6363

6464
# This parent fixture is intentionally left unannotated to guarantee that
6565
# this parent (rather than this child) fixture is type-checked as invalid.
66-
fixture_async_nongenerator_bad,
66+
fixture_async_nongen_bad,
6767
) -> str:
6868
'''
6969
Asynchronous non-generator fixture annotated by a correct return hint but
@@ -78,10 +78,10 @@ async def fixture_async_nongenerator_needs_fixtures_bad(
7878

7979

8080
@fixture
81-
async def fixture_async_nongenerator_bad_needs_fixtures(
81+
async def fixture_async_nongen_bad_needs_fixtures(
8282
# Two or more parent fixtures that are *ALL* incorrectly annotated.
83-
fixture_async_nongenerator: int,
84-
fixture_async_nongenerator_needs_fixture: int,
83+
fixture_async_nongen: int,
84+
fixture_async_nongen_needs_fixture: int,
8585
) -> str:
8686
'''
8787
Asynchronous non-generator fixture annotated by a correct return hint but
@@ -102,7 +102,7 @@ async def fixture_async_nongenerator_bad_needs_fixtures(
102102
# Asynchronous generator root fixtures requiring *NO* other fixtures.
103103

104104
@fixture
105-
async def fixture_async_generator() -> AsyncIterable[str]:
105+
async def fixture_async_gen() -> AsyncIterable[str]:
106106
'''
107107
Asynchronous generator fixture annotated by a correct return hint.
108108
'''
@@ -112,7 +112,7 @@ async def fixture_async_generator() -> AsyncIterable[str]:
112112

113113

114114
@fixture
115-
async def fixture_async_generator_bad() -> AsyncIterable[int]:
115+
async def fixture_async_gen_bad_call() -> AsyncIterable[int]:
116116
'''
117117
Asynchronous generator fixture annotated by an incorrect return hint.
118118
'''
@@ -124,26 +124,26 @@ async def fixture_async_generator_bad() -> AsyncIterable[int]:
124124
# Asynchronous generator leaf fixtures requiring one or more other such fixtures.
125125

126126
@fixture
127-
async def fixture_async_generator_needs_fixture(
128-
fixture_async_generator: str) -> AsyncIterable[str]:
127+
async def fixture_async_gen_needs_fixture(
128+
fixture_async_gen: str) -> AsyncIterable[str]:
129129
'''
130130
Asynchronous generator fixture requiring another such fixture annotated
131131
by the same parameter hint as the return hint annotating the latter fixture.
132132
'''
133133

134134
# Yield an object satisfying the return hint annotating this fixture.
135-
yield fixture_async_generator
135+
yield fixture_async_gen
136136

137137

138138
@fixture
139-
async def fixture_async_generator_needs_fixtures_bad(
139+
async def fixture_async_gen_needs_fixtures_bad_call(
140140
# Two or more parent fixtures that are *ALL* correctly annotated.
141-
fixture_async_generator: str,
142-
fixture_async_generator_needs_fixture: str,
141+
fixture_async_gen: str,
142+
fixture_async_gen_needs_fixture: str,
143143

144144
# This parent fixture is intentionally left unannotated to guarantee that
145145
# this parent (rather than this child) fixture is type-checked as invalid.
146-
fixture_async_generator_bad,
146+
fixture_async_gen_bad_call,
147147
) -> AsyncIterable[str]:
148148
'''
149149
Asynchronous generator fixture annotated by a correct return hint but
@@ -158,10 +158,10 @@ async def fixture_async_generator_needs_fixtures_bad(
158158

159159

160160
@fixture
161-
async def fixture_async_generator_bad_needs_fixtures(
161+
async def fixture_async_gen_bad_needs_fixtures(
162162
# Two or more parent fixtures that are *ALL* incorrectly annotated.
163-
fixture_async_generator: int,
164-
fixture_async_generator_needs_fixture: int,
163+
fixture_async_gen: int,
164+
fixture_async_gen_needs_fixture: int,
165165
) -> AsyncIterable[str]:
166166
'''
167167
Asynchronous generator fixture annotated by a correct return hint but

pytest_beartype_test/a90_func/data/_fixture/fixsync.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# Synchronous non-generator root fixtures requiring *NO* other fixtures.
2222

2323
@fixture
24-
def fixture_sync_nongenerator() -> str:
24+
def fixture_sync_nongen() -> str:
2525
'''
2626
Synchronous non-generator fixture annotated by a correct return hint.
2727
'''
@@ -31,7 +31,7 @@ def fixture_sync_nongenerator() -> str:
3131

3232

3333
@fixture
34-
def fixture_sync_nongenerator_bad() -> int:
34+
def fixture_sync_nongen_bad_call() -> int:
3535
'''
3636
Synchronous non-generator fixture annotated by an incorrect return hint.
3737
'''
@@ -44,26 +44,26 @@ def fixture_sync_nongenerator_bad() -> int:
4444
# fixtures.
4545

4646
@fixture
47-
def fixture_sync_nongenerator_needs_fixture(
48-
fixture_sync_nongenerator: str) -> str:
47+
def fixture_sync_nongen_needs_fixture(
48+
fixture_sync_nongen: str) -> str:
4949
'''
5050
Synchronous non-generator fixture requiring another such fixture annotated
5151
by the same parameter hint as the return hint annotating the latter fixture.
5252
'''
5353

5454
# Return an object satisfying the return hint annotating this fixture.
55-
return fixture_sync_nongenerator
55+
return fixture_sync_nongen
5656

5757

5858
@fixture
59-
def fixture_sync_nongenerator_needs_fixtures_bad(
59+
def fixture_sync_nongen_needs_fixtures_bad_call(
6060
# Two or more parent fixtures that are *ALL* correctly annotated.
61-
fixture_sync_nongenerator: str,
62-
fixture_sync_nongenerator_needs_fixture: str,
61+
fixture_sync_nongen: str,
62+
fixture_sync_nongen_needs_fixture: str,
6363

6464
# This parent fixture is intentionally left unannotated to guarantee that
6565
# this parent (rather than this child) fixture is type-checked as invalid.
66-
fixture_sync_nongenerator_bad,
66+
fixture_sync_nongen_bad_call,
6767
) -> str:
6868
'''
6969
Synchronous non-generator fixture annotated by a correct return hint but
@@ -78,10 +78,10 @@ def fixture_sync_nongenerator_needs_fixtures_bad(
7878

7979

8080
@fixture
81-
def fixture_sync_nongenerator_bad_needs_fixtures(
81+
def fixture_sync_nongen_bad_needs_fixtures(
8282
# Two or more parent fixtures that are *ALL* incorrectly annotated.
83-
fixture_sync_nongenerator: int,
84-
fixture_sync_nongenerator_needs_fixture: int,
83+
fixture_sync_nongen: int,
84+
fixture_sync_nongen_needs_fixture: int,
8585
) -> str:
8686
'''
8787
Synchronous non-generator fixture annotated by a correct return hint but
@@ -102,7 +102,7 @@ def fixture_sync_nongenerator_bad_needs_fixtures(
102102
# Synchronous generator root fixtures requiring *NO* other fixtures.
103103

104104
@fixture
105-
def fixture_sync_generator() -> Iterable[str]:
105+
def fixture_sync_gen() -> Iterable[str]:
106106
'''
107107
Synchronous generator fixture annotated by a correct return hint.
108108
'''
@@ -112,7 +112,7 @@ def fixture_sync_generator() -> Iterable[str]:
112112

113113

114114
@fixture
115-
def fixture_sync_generator_bad() -> Iterable[int]:
115+
def fixture_sync_gen_bad_call() -> Iterable[int]:
116116
'''
117117
Synchronous generator fixture annotated by an incorrect return hint.
118118
'''
@@ -124,26 +124,26 @@ def fixture_sync_generator_bad() -> Iterable[int]:
124124
# Synchronous generator leaf fixtures requiring one or more other such fixtures.
125125

126126
@fixture
127-
def fixture_sync_generator_needs_fixture(
128-
fixture_sync_generator: str) -> Iterable[str]:
127+
def fixture_sync_gen_needs_fixture(
128+
fixture_sync_gen: str) -> Iterable[str]:
129129
'''
130130
Synchronous generator fixture requiring another such fixture annotated
131131
by the same parameter hint as the return hint annotating the latter fixture.
132132
'''
133133

134134
# Yield an object satisfying the return hint annotating this fixture.
135-
yield fixture_sync_generator
135+
yield fixture_sync_gen
136136

137137

138138
@fixture
139-
def fixture_sync_generator_needs_fixtures_bad(
139+
def fixture_sync_gen_needs_fixtures_bad_call(
140140
# Two or more parent fixtures that are *ALL* correctly annotated.
141-
fixture_sync_generator: str,
142-
fixture_sync_generator_needs_fixture: str,
141+
fixture_sync_gen: str,
142+
fixture_sync_gen_needs_fixture: str,
143143

144144
# This parent fixture is intentionally left unannotated to guarantee that
145145
# this parent (rather than this child) fixture is type-checked as invalid.
146-
fixture_sync_generator_bad,
146+
fixture_sync_gen_bad_call,
147147
) -> Iterable[str]:
148148
'''
149149
Synchronous generator fixture annotated by a correct return hint but
@@ -158,10 +158,10 @@ def fixture_sync_generator_needs_fixtures_bad(
158158

159159

160160
@fixture
161-
def fixture_sync_generator_bad_needs_fixtures(
161+
def fixture_sync_gen_bad_needs_fixtures(
162162
# Two or more parent fixtures that are *ALL* incorrectly annotated.
163-
fixture_sync_generator: int,
164-
fixture_sync_generator_needs_fixture: int,
163+
fixture_sync_gen: int,
164+
fixture_sync_gen_needs_fixture: int,
165165
) -> Iterable[str]:
166166
'''
167167
Synchronous generator fixture annotated by a correct return hint but

0 commit comments

Comments
 (0)