Skip to content

Commit bbe54a7

Browse files
kmikedavidfritzsche
authored andcommitted
support async def tests
1 parent 031514f commit bbe54a7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/pytest_mypy_testing/parser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ class MypyTestItem:
2424
lineno: int
2525
end_lineno: int
2626
expected_messages: List[Message]
27-
func_node: Optional[ast.FunctionDef] = None
27+
func_node: Optional[Union[ast.FunctionDef, ast.AsyncFunctionDef]] = None
2828
marks: Set[str] = dataclasses.field(default_factory=lambda: set())
2929
actual_messages: List[Message] = dataclasses.field(default_factory=lambda: [])
3030

3131
@classmethod
3232
def from_ast_node(
3333
cls,
34-
func_node: ast.FunctionDef,
34+
func_node: Union[ast.FunctionDef, ast.AsyncFunctionDef],
3535
marks: Optional[Set[str]] = None,
3636
unfiltered_messages: Optional[Iterable[Message]] = None,
3737
) -> "MypyTestItem":
38-
if not isinstance(func_node, ast.FunctionDef):
38+
if not isinstance(func_node, (ast.FunctionDef, ast.AsyncFunctionDef)):
3939
raise ValueError(
4040
f"Invalid func_node type: Got {type(func_node)}, "
41-
f"expected {ast.FunctionDef}"
41+
f"expected {ast.FunctionDef} or {ast.AsyncFunctionDef}"
4242
)
4343
lineno = func_node.lineno
4444
end_lineno = getattr(func_node, "end_lineno", 0)
@@ -121,7 +121,7 @@ def parse_file(filename: Union[os.PathLike, str, pathlib.Path], config) -> MypyT
121121
items: List[MypyTestItem] = []
122122

123123
for node in ast.iter_child_nodes(tree):
124-
if not isinstance(node, ast.FunctionDef):
124+
if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
125125
continue
126126
marks = _find_marks(node)
127127
if "mypy_testing" in marks:

0 commit comments

Comments
 (0)