diff --git a/pytest_mypy_plugins/tests/test-regex_assertions.yml b/pytest_mypy_plugins/tests/test-regex_assertions.yml index 6752e16..c16e5d7 100644 --- a/pytest_mypy_plugins/tests/test-regex_assertions.yml +++ b/pytest_mypy_plugins/tests/test-regex_assertions.yml @@ -15,6 +15,20 @@ out: | main:2: note: .*str.* +- case: regex_with_out_does_not_hang + expect_fail: yes + regex: yes + main: | + 'abc'.split(4) + out: | + main:1: error: Argument 1 to "split" of "str" has incompatible type "int"; expected "Optional[str]" + +- case: regex_with_comment_does_not_hang + expect_fail: yes + regex: yes + main: | + a = 'abc'.split(4) # E: Argument 1 to "split" of "str" has incompatible type "int"; expected "Optional[str]" + - case: expected_single_message_regex regex: no main: | @@ -34,7 +48,7 @@ a = 'hello' reveal_type(a) # N: .*str.* -- case: regext_does_not_match +- case: regex_does_not_match expect_fail: yes regex: no main: | diff --git a/pytest_mypy_plugins/utils.py b/pytest_mypy_plugins/utils.py index 437361d..837b3d7 100644 --- a/pytest_mypy_plugins/utils.py +++ b/pytest_mypy_plugins/utils.py @@ -144,6 +144,8 @@ def _add_aligned_message(s1: str, s2: str, error_message: str) -> str: error_message += "Alignment of first line difference:\n" + assert s1 != s2 + trunc = False while s1[:30] == s2[:30]: s1 = s1[10:] @@ -260,7 +262,9 @@ def format_error_lines(lines: List[str]) -> str: format_error_lines(actual_message_lines), format_error_lines(expected_message_lines) ) - if ( + if expected_line and expected_line.regex: + error_message += "The actual output does not match the expected regex." + elif ( first_diff_actual is not None and first_diff_expected is not None and (