Skip to content

Commit d40b064

Browse files
committed
fix tests, add fixture logic
1 parent fcc89d2 commit d40b064

File tree

8 files changed

+63
-154
lines changed

8 files changed

+63
-154
lines changed

Diff for: flake8_async/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939

4040
# CalVer: YY.month.patch, e.g. first release of July 2022 == "22.7.1"
41-
__version__ = "24.10.2"
41+
__version__ = "24.10.3"
4242

4343

4444
# taken from https://github.com/Zac-HD/shed

Diff for: flake8_async/visitors/visitor91x.py

+12
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ def leave_FunctionDef(
9595
original_node.asynchronous is not None
9696
and not self.has_await
9797
and not func_empty_body(original_node)
98+
and not func_has_decorator(original_node, "overload")
99+
# skip functions named 'text_xxx' with params, since they may be relying
100+
# on async fixtures. This is esp bad as sync funcs relying on async fixtures
101+
# is not well handled: https://github.com/pytest-dev/pytest/issues/10839
102+
# also skip funcs with @fixtures and params
103+
and not (
104+
original_node.params.params
105+
and (
106+
original_node.name.value.startswith("test_")
107+
or func_has_decorator(original_node, "fixture")
108+
)
109+
)
98110
):
99111
self.error(original_node)
100112
self.restore_state(original_node)

Diff for: tests/autofix_files/async124.py

-87
This file was deleted.

Diff for: tests/autofix_files/async124.py.diff

-49
This file was deleted.

Diff for: tests/autofix_files/async910.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,12 @@ def foo_normal_func_1():
134134
def foo_normal_func_2(): ...
135135

136136

137-
# overload decorator
137+
# overload decorator is skipped
138+
# overload functions should always be empty, so the check is somewhat redundant,
139+
# but making one non-empty to check the logic.
138140
@overload
139-
async def foo_overload_1(_: bytes): ...
141+
async def foo_overload_1(_: bytes):
142+
raise NotImplementedError
140143

141144

142145
@typing.overload

Diff for: tests/eval_files/async124.py

+32-12
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# 910/911 will also autofix async124, in the sense of adding a checkpoint. This is perhaps
77
# not what the user wants though, so this would be a case in favor of making 910/911 not
88
# trigger when async124 does.
9-
# AUTOFIX
10-
# ASYNCIO_NO_AUTOFIX
11-
from typing import Any
9+
# NOAUTOFIX # all errors get "fixed" except for foo_fix_no_subfix
10+
from typing import Any, overload
11+
from pytest import fixture
1212

1313

1414
def condition() -> bool:
@@ -66,16 +66,36 @@ async def foo_empty_pass():
6666
pass
6767

6868

69-
# we could consider filtering out functions named `test_.*` to not give false alarms on
70-
# tests that use async fixtures.
71-
# For ruff and for running through flake8 we could expect users to use per-file-ignores,
72-
# but running as standalone we don't currently support that. (though probs wouldn't be
73-
# too bad to add support).
7469
# See e.g. https://github.com/agronholm/anyio/issues/803 for why one might want an async
7570
# test without awaits.
71+
async def test_async_fixture(
72+
my_async_fixture,
73+
): # ASYNC910: 0, "exit", Statement("function definition", lineno)
74+
assert my_async_fixture.setup_worked_correctly
7675

7776

78-
async def test_async_fixture(
79-
my_anyio_fixture,
80-
): # ASYNC124: 0 # ASYNC910: 0, "exit", Statement("function definition", lineno)
81-
assert my_anyio_fixture.setup_worked_correctly
77+
# no params -> no async fixtures
78+
async def test_no_fixture(): # ASYNC124: 0 # ASYNC910: 0, "exit", Statement("function definition", lineno)
79+
print("blah")
80+
81+
82+
# skip @overload. They should always be empty, but /shrug
83+
@overload
84+
async def foo_overload():
85+
print("blah")
86+
87+
88+
async def foo_overload(): ...
89+
90+
91+
# skip @[pytest.]fixture if they have any params, since they might depend on other
92+
# async fixtures
93+
@fixture
94+
async def foo_fix(my_async_fixture):
95+
print("blah")
96+
97+
98+
# but @fixture with no params can be converted to sync
99+
@fixture
100+
async def foo_fix_no_subfix(): # ASYNC124: 0
101+
print("blah")

Diff for: tests/eval_files/async910.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,12 @@ def foo_normal_func_1():
126126
def foo_normal_func_2(): ...
127127

128128

129-
# overload decorator
129+
# overload decorator is skipped
130+
# overload functions should always be empty, so the check is somewhat redundant,
131+
# but making one non-empty to check the logic.
130132
@overload
131-
async def foo_overload_1(_: bytes): ...
133+
async def foo_overload_1(_: bytes):
134+
raise NotImplementedError
132135

133136

134137
@typing.overload

Diff for: tests/trio_options.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
"""Test file used in tests/test_decator.py to check decorator and command line."""
22

3+
import asyncio
4+
35
app = None
46

57

8+
def condition() -> bool:
9+
return False
10+
11+
612
@app.route # type: ignore
713
async def f():
8-
print("hello world")
14+
if condition():
15+
await asyncio.sleep(0)

0 commit comments

Comments
 (0)