|
1 | 1 | import collections
|
2 | 2 | import os
|
| 3 | +import re |
3 | 4 | import subprocess
|
4 | 5 | import sys
|
5 | 6 | from pathlib import Path
|
|
18 | 19 | DOC_URI = f"file:/{Path(__file__)}"
|
19 | 20 | DOC_TYPE_ERR = """{}.append(3)
|
20 | 21 | """
|
21 |
| -TYPE_ERR_MSG = '"Dict[<nothing>, <nothing>]" has no attribute "append"' |
| 22 | + |
| 23 | +# Mypy 1.7 changed <nothing> into "Never", so make this a regex to be compatible |
| 24 | +# with multiple versions of mypy |
| 25 | +TYPE_ERR_MSG_REGEX = r"\"Dict\[(.+)]\" has no attribute \"append\"" |
22 | 26 |
|
23 | 27 | TEST_LINE = 'test_plugin.py:279:8:279:16: error: "Request" has no attribute "id" [attr-defined]'
|
24 | 28 | TEST_LINE_NOTE = (
|
@@ -66,7 +70,7 @@ def test_plugin(workspace, last_diagnostics_monkeypatch):
|
66 | 70 |
|
67 | 71 | assert len(diags) == 1
|
68 | 72 | diag = diags[0]
|
69 |
| - assert diag["message"] == TYPE_ERR_MSG |
| 73 | + assert re.search(TYPE_ERR_MSG_REGEX, diag["message"]) |
70 | 74 | assert diag["range"]["start"] == {"line": 0, "character": 0}
|
71 | 75 | # Running mypy in 3.7 produces wrong error ends this can be removed when 3.7 reaches EOL
|
72 | 76 | if sys.version_info < (3, 8):
|
@@ -365,7 +369,7 @@ def test_config_exclude(tmpdir, workspace):
|
365 | 369 | plugin.pylsp_settings(workspace._config)
|
366 | 370 | workspace.update_config({"pylsp": {"plugins": {"pylsp_mypy": {}}}})
|
367 | 371 | diags = plugin.pylsp_lint(workspace._config, workspace, doc, is_saved=False)
|
368 |
| - assert diags[0]["message"] == TYPE_ERR_MSG |
| 372 | + assert re.search(TYPE_ERR_MSG_REGEX, diags[0]["message"]) |
369 | 373 |
|
370 | 374 | # Add the path of our document to the exclude patterns
|
371 | 375 | exclude_path = doc.path.replace(os.sep, "/")
|
|
0 commit comments