Skip to content

Commit 2dfef3b

Browse files
committed
Tighten regex for output assertion parsing
The `severity` group was permissive enough to also capture parts of the message text if that contained any colons. Update it to only capture (ASCII) words, and update preceding groups to match at least 1 character. Fixes #155
1 parent b9437c8 commit 2dfef3b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pytest_mypy_plugins/tests/test-regex-assertions.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,18 @@
5454
main: |
5555
a = 'hello'
5656
reveal_type(a) # NR: .*banana.*
57+
58+
- case: regex_against_callable_comment
59+
main: |
60+
def foo(bar: str, ham: int = 42) -> set[str | int]:
61+
return {bar, ham}
62+
reveal_type(foo) # NR: Revealed type is "def \(bar: builtins\.str, ham: builtins\.int =\) -> .*"
63+
64+
- case: regex_against_callable_out
65+
regex: yes
66+
main: |
67+
def foo(bar: str, ham: int = 42) -> set[str | int]:
68+
return {bar, ham}
69+
reveal_type(foo)
70+
out: |
71+
main:3: note: Revealed type is "def \(bar: builtins\.str, ham: builtins\.int =\) -> .*"

pytest_mypy_plugins/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def extract_output_matchers_from_out(out: str, params: Mapping[str, Any], regex:
326326
lines = render_template(out, params).split("\n")
327327
for line in lines:
328328
match = re.search(
329-
r"^(?P<fname>.*):(?P<lnum>\d*): (?P<severity>.*):((?P<col>\d+):)? (?P<message>.*)$", line.strip()
329+
r"^(?P<fname>.+):(?P<lnum>\d+): (?P<severity>[A-Za-z]+):((?P<col>\d+):)? (?P<message>.*)$", line.strip()
330330
)
331331
if match:
332332
if match.group("severity") == "E":

0 commit comments

Comments
 (0)