Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/pytest_mypy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def pytest_addoption(parser: pytest.Parser) -> None:
type=str,
help="adds custom mypy config file",
)
group.addoption(
"--mypy-no-status-check",
action="store_true",
help="ignore mypy's exit status",
)


def _xdist_worker(config: pytest.Config) -> Dict[str, Any]:
Expand Down Expand Up @@ -164,6 +169,7 @@ def pytest_collect_file(
parent.config.option.mypy,
parent.config.option.mypy_config_file,
parent.config.option.mypy_ignore_missing_imports,
parent.config.option.mypy_no_status_check,
],
):
# Do not create MypyFile instance for a .py file if a
Expand All @@ -183,7 +189,9 @@ def collect(self) -> Iterator[MypyItem]:
# Since mypy might check files that were not collected,
# pytest could pass even though mypy failed!
# To prevent that, add an explicit check for the mypy exit status.
if not any(isinstance(item, MypyStatusItem) for item in self.session.items):
if not self.session.config.option.mypy_no_status_check and not any(
isinstance(item, MypyStatusItem) for item in self.session.items
):
yield MypyStatusItem.from_parent(
parent=self,
name=nodeid_name + "-status",
Expand Down
13 changes: 13 additions & 0 deletions tests/test_pytest_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,16 @@ def test_py_typed(testdir):
testdir.makepyfile(**{name: "import pytest_mypy"})
result = testdir.run("mypy", f"{name}.py")
assert result.ret == 0


def test_mypy_no_status_check(testdir, xdist_args):
"""Verify that --mypy-no-status-check disables MypyStatusItem collection."""
testdir.makepyfile(thon="one: int = 1")
result = testdir.runpytest_subprocess("--mypy", *xdist_args)
mypy_file_checks = 1
mypy_status_check = 1
result.assert_outcomes(passed=mypy_file_checks + mypy_status_check)
assert result.ret == pytest.ExitCode.OK
result = testdir.runpytest_subprocess("--mypy-no-status-check", *xdist_args)
result.assert_outcomes(passed=mypy_file_checks)
assert result.ret == pytest.ExitCode.OK