diff --git a/pytest_mypy_plugins/tests/test-regex-assertions.yml b/pytest_mypy_plugins/tests/test-regex-assertions.yml index c16e5d7..2e8806b 100644 --- a/pytest_mypy_plugins/tests/test-regex-assertions.yml +++ b/pytest_mypy_plugins/tests/test-regex-assertions.yml @@ -54,3 +54,18 @@ main: | a = 'hello' reveal_type(a) # NR: .*banana.* + +- case: regex_against_callable_comment + main: | + def foo(bar: str, ham: int = 42) -> set[str | int]: + return {bar, ham} + reveal_type(foo) # NR: Revealed type is "def \(bar: builtins\.str, ham: builtins\.int =\) -> .*" + +- case: regex_against_callable_out + regex: yes + main: | + def foo(bar: str, ham: int = 42) -> set[str | int]: + return {bar, ham} + reveal_type(foo) + out: | + main:3: note: Revealed type is "def \(bar: builtins\.str, ham: builtins\.int =\) -> .*" diff --git a/pytest_mypy_plugins/utils.py b/pytest_mypy_plugins/utils.py index 6eb3d1f..d755508 100644 --- a/pytest_mypy_plugins/utils.py +++ b/pytest_mypy_plugins/utils.py @@ -326,7 +326,7 @@ def extract_output_matchers_from_out(out: str, params: Mapping[str, Any], regex: lines = render_template(out, params).split("\n") for line in lines: match = re.search( - r"^(?P.*):(?P\d*): (?P.*):((?P\d+):)? (?P.*)$", line.strip() + r"^(?P.+):(?P\d+): (?P[A-Za-z]+):((?P\d+):)? (?P.*)$", line.strip() ) if match: if match.group("severity") == "E":