Skip to content
Closed
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: 10 additions & 0 deletions src/pytest_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,30 @@ def pytest_runtestloop(session):

if stderr:
terminal.write_line(stderr, red=True)
MypyItem.MYPY_RUN_COMPLETE = True


class MypyItem(pytest.Item, pytest.File):

"""A File that Mypy Runs On."""

MARKER = 'mypy'
MYPY_RUN_COMPLETE=False

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.add_marker(self.MARKER)
self.mypy_errors = []

def runtest(self):
if not MypyItem.MYPY_RUN_COMPLETE:
stdout, stderr, status = mypy.api.run(
mypy_argv + [ str(self.fspath) ],
)

if status != 0:
raise MypyError(stdout)

"""Raise an exception if mypy found errors for this item."""
if self.mypy_errors:
raise MypyError('\n'.join(self.mypy_errors))
Expand Down