8000 Inject a test that checks the mypy exit status by dmtucker · Pull Request #79 · realpython/pytest-mypy · GitHub
[go: up one dir, main page]

Skip to content

Inject a test that checks the mypy exit status #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 8, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add _mypy_results
  • Loading branch information
dmtucker committed Mar 1, 2020
commit 6cd5304b7212dafe057ea2fe1822927a8748d818
36 changes: 21 additions & 15 deletions src/pytest_mypy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Mypy static type checker plugin for Pytest"""

import functools
import json
import os
from tempfile import NamedTemporaryFile
Expand Down Expand Up @@ -115,21 +116,7 @@ class MypyFileItem(MypyItem, pytest.File):

def runtest(self):
"""Raise an exception if mypy found errors for this item."""
results = _cached_json_results(
results_path=(
self.config._mypy_results_path
if _is_master(self.config) else
self.config.slaveinput['_mypy_results_path']
),
results_factory=lambda:
_mypy_results_factory(
abspaths=[
os.path.abspath(str(item.fspath))
for item in self.session.items
if isinstance(item, MypyFileItem)
],
)
)
results = _mypy_results(self.session)
abspath = os.path.abspath(str(self.fspath))
errors = results['abspath_errors'].get(abspath)
if errors:
Expand All @@ -144,6 +131,25 @@ def reportinfo(self):
)


def _mypy_results(session):
"""Get the cached mypy results for the session, or generate them."""
return _cached_json_results(
results_path=(
session.config._mypy_results_path
if _is_master(session.config) else
session.config.slaveinput['_mypy_results_path']
),
results_factory=functools.partial(
_mypy_results_factory,
abspaths=[
os.path.abspath(str(item.fspath))
for item in session.items
if isinstance(item, MypyFileItem)
],
)
)


def _cached_json_results(results_path, results_factory=None):
"""
Read results from results_path if it exists;
Expand Down
0