(path: str)
| 157 | @pytest.mark.skipif(NO_MYPY, reason="Mypy is not installed") |
| 158 | @pytest.mark.parametrize("path", get_test_cases(FAIL_DIR)) |
| 159 | def test_fail(path: str) -> None: |
| 160 | __tracebackhide__ = True |
| 161 | |
| 162 | with open(path) as fin: |
| 163 | lines = fin.readlines() |
| 164 | |
| 165 | errors = defaultdict(lambda: "") |
| 166 | |
| 167 | output_mypy = OUTPUT_MYPY |
| 168 | assert path in output_mypy |
| 169 | |
| 170 | for error_line in output_mypy[path]: |
| 171 | lineno, error_line = _strip_filename(error_line) |
| 172 | errors[lineno] += f'{error_line}\n' |
| 173 | |
| 174 | for i, line in enumerate(lines): |
| 175 | lineno = i + 1 |
| 176 | if ( |
| 177 | line.startswith('#') |
| 178 | or (" E:" not in line and lineno not in errors) |
| 179 | ): |
| 180 | continue |
| 181 | |
| 182 | target_line = lines[lineno - 1] |
| 183 | if "# E:" in target_line: |
| 184 | expression, _, marker = target_line.partition(" # E: ") |
| 185 | expected_error = errors[lineno].strip() |
| 186 | marker = marker.strip() |
| 187 | _test_fail(path, expression, marker, expected_error, lineno) |
| 188 | else: |
| 189 | pytest.fail( |
| 190 | f"Unexpected mypy output at line {lineno}\n\n{errors[lineno]}" |
| 191 | ) |
| 192 | |
| 193 | |
| 194 | _FAIL_MSG1 = """Extra error at line {} |
nothing calls this directly
no test coverage detected