From c0f1bb3b34661e303d1c6d770b4edfcc08a917a5 Mon Sep 17 00:00:00 2001 From: David Tucker Date: Sun, 11 Dec 2022 09:58:16 -0800 Subject: [PATCH 1/2] Update the validation GH Action ubuntu-20.04 is required for py36 now. --- .github/workflows/validation.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index 3ef36e0..cca2f1d 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -2,13 +2,13 @@ name: Validation on: [push, pull_request] jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: matrix: python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - run: python -m pip install --upgrade tox-gh-actions From a8637bbbc3f3ca81b29b0a7227d1d71c18f9155e Mon Sep 17 00:00:00 2001 From: David Tucker Date: Sat, 12 Nov 2022 13:41:07 -0800 Subject: [PATCH 2/2] Stop failing if mypy only produces notes --- changelog.md | 3 +++ src/pytest_mypy.py | 13 ++++++++++++- tests/test_pytest_mypy.py | 27 +++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 7fdccf1..d0393fe 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changelog +## [0.10.3](https://github.com/dbader/pytest-mypy/milestone/21) +* Stop failing if mypy only produces notes. + ## [0.10.2](https://github.com/dbader/pytest-mypy/milestone/20) * Update and loosen [build-system] requirements. diff --git a/src/pytest_mypy.py b/src/pytest_mypy.py index 668e9f1..faa02a7 100644 --- a/src/pytest_mypy.py +++ b/src/pytest_mypy.py @@ -5,6 +5,7 @@ from pathlib import Path from tempfile import NamedTemporaryFile from typing import Dict, List, Optional, TextIO +import warnings import attr from filelock import FileLock # type: ignore @@ -202,7 +203,13 @@ def runtest(self): abspath = os.path.abspath(str(self.fspath)) errors = results.abspath_errors.get(abspath) if errors: - raise MypyError(file_error_formatter(self, results, errors)) + if not all( + error.partition(":")[2].partition(":")[0].strip() == "note" + for error in errors + ): + raise MypyError(file_error_formatter(self, results, errors)) + # This line cannot be easily covered on mypy < 0.990: + warnings.warn("\n" + "\n".join(errors), MypyWarning) # pragma: no cover def reportinfo(self): """Produce a heading for the test report.""" @@ -314,6 +321,10 @@ class MypyError(Exception): """ +class MypyWarning(pytest.PytestWarning): + """A non-failure message regarding the mypy run.""" + + def pytest_terminal_summary(terminalreporter, config): """Report stderr and unrecognized lines from stdout.""" try: diff --git a/tests/test_pytest_mypy.py b/tests/test_pytest_mypy.py index 0f10dc5..6e86af3 100644 --- a/tests/test_pytest_mypy.py +++ b/tests/test_pytest_mypy.py @@ -98,6 +98,33 @@ def pyfunc(x: int) -> str: assert result.ret != 0 +def test_mypy_annotation_unchecked(testdir, xdist_args): + """Verify that annotation-unchecked warnings do not manifest as an error.""" + testdir.makepyfile( + """ + def pyfunc(x): + y: int = 2 + return x * y + """, + ) + result = testdir.runpytest_subprocess(*xdist_args) + result.assert_outcomes() + result = testdir.runpytest_subprocess("--mypy", *xdist_args) + mypy_file_checks = 1 + mypy_status_check = 1 + mypy_checks = mypy_file_checks + mypy_status_check + outcomes = {"passed": mypy_checks} + # mypy doesn't emit annotation-unchecked warnings until 0.990: + min_mypy_version = Version("0.990") + if MYPY_VERSION >= min_mypy_version and PYTEST_VERSION >= Version("7.0"): + # assert_outcomes does not support `warnings` until 7.x. + outcomes["warnings"] = 1 + result.assert_outcomes(**outcomes) + if MYPY_VERSION >= min_mypy_version: + result.stdout.fnmatch_lines(["*MypyWarning*"]) + assert result.ret == 0 + + def test_mypy_ignore_missings_imports(testdir, xdist_args): """ Verify that --mypy-ignore-missing-imports