Skip to content

Commit 23131ba

Browse files
authored
Merge pull request #179 from dmtucker/issue176
Add --mypy-no-status-check
2 parents abda733 + 69aeb48 commit 23131ba

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/pytest_mypy/__init__.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ def pytest_addoption(parser: pytest.Parser) -> None:
8484
type=str,
8585
help="adds custom mypy config file",
8686
)
87+
group.addoption(
88+
"--mypy-no-status-check",
89+
action="store_true",
90+
help="ignore mypy's exit status",
91+
)
8792

8893

8994
def _xdist_worker(config: pytest.Config) -> Dict[str, Any]:
@@ -164,6 +169,7 @@ def pytest_collect_file(
164169
parent.config.option.mypy,
165170
parent.config.option.mypy_config_file,
166171
parent.config.option.mypy_ignore_missing_imports,
172+
parent.config.option.mypy_no_status_check,
167173
],
168174
):
169175
# Do not create MypyFile instance for a .py file if a
@@ -183,7 +189,9 @@ def collect(self) -> Iterator[MypyItem]:
183189
# Since mypy might check files that were not collected,
184190
# pytest could pass even though mypy failed!
185191
# To prevent that, add an explicit check for the mypy exit status.
186-
if not any(isinstance(item, MypyStatusItem) for item in self.session.items):
192+
if not self.session.config.option.mypy_no_status_check and not any(
193+
isinstance(item, MypyStatusItem) for item in self.session.items
194+
):
187195
yield MypyStatusItem.from_parent(
188196
parent=self,
189197
name=nodeid_name + "-status",

tests/test_pytest_mypy.py

+13
Original file line numberDiff line numberDiff line change
@@ -548,3 +548,16 @@ def test_py_typed(testdir):
548548
testdir.makepyfile(**{name: "import pytest_mypy"})
549549
result = testdir.run("mypy", f"{name}.py")
550550
assert result.ret == 0
551+
552+
553+
def test_mypy_no_status_check(testdir, xdist_args):
554+
"""Verify that --mypy-no-status-check disables MypyStatusItem collection."""
555+
testdir.makepyfile(thon="one: int = 1")
556+
result = testdir.runpytest_subprocess("--mypy", *xdist_args)
557+
mypy_file_checks = 1
558+
mypy_status_check = 1
559+
result.assert_outcomes(passed=mypy_file_checks + mypy_status_check)
560+
assert result.ret == pytest.ExitCode.OK
561+
result = testdir.runpytest_subprocess("--mypy-no-status-check", *xdist_args)
562+
result.assert_outcomes(passed=mypy_file_checks)
563+
assert result.ret == pytest.ExitCode.OK

0 commit comments

Comments
 (0)