Skip to content

Commit

Permalink
Merge pull request #38 from dmtucker/coverage
Browse files Browse the repository at this point in the history
Require 100% code coverage
  • Loading branch information
dmtucker committed Jun 23, 2019
2 parents 26e866e + 6b9bff5 commit 89d5e10
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
36 changes: 28 additions & 8 deletions tests/test_pytest_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ def myfunc(x: int) -> int:
return x * 2
''')
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines(['* no tests ran *'])
assert result.ret != 0
result.assert_outcomes()
result = testdir.runpytest_subprocess('--mypy')
result.stdout.fnmatch_lines(['* 1 passed *'])
result.assert_outcomes(passed=1)
assert result.ret == 0


Expand All @@ -18,10 +17,12 @@ def test_mypy_error(testdir):
def myfunc(x: int) -> str:
return x * 2
''')
result = testdir.runpytest_subprocess()
result.assert_outcomes()
result = testdir.runpytest_subprocess('--mypy')
result.assert_outcomes(failed=1)
result.stdout.fnmatch_lines([
'test_mypy_error.py:2: error: Incompatible return value*',
'* 1 failed *',
])
assert result.ret != 0

Expand All @@ -35,13 +36,13 @@ def test_mypy_ignore_missings_imports(testdir):
import pytest_mypy
''')
result = testdir.runpytest_subprocess('--mypy')
result.assert_outcomes(failed=1)
result.stdout.fnmatch_lines([
'*1: error: Cannot find module named*',
'* 1 failed *',
])
assert result.ret != 0
result = testdir.runpytest_subprocess('--mypy-ignore-missing-imports')
result.stdout.fnmatch_lines(['* 1 passed *'])
result.assert_outcomes(passed=1)
assert result.ret == 0


Expand All @@ -52,8 +53,27 @@ def test_fails():
assert False
''')
result = testdir.runpytest_subprocess('--mypy')
result.stdout.fnmatch_lines(['* 1 failed, 1 passed *'])
result.assert_outcomes(failed=1, passed=1)
assert result.ret != 0
result = testdir.runpytest_subprocess('--mypy', '-m', 'mypy')
result.stdout.fnmatch_lines(['* 1 passed, 1 deselected *'])
result.assert_outcomes(passed=1)
assert result.ret == 0


def test_non_mypy_error(testdir):
"""Verify that non-MypyError exceptions are passed through the plugin."""
message = 'This is not a MypyError.'
testdir.makepyfile('''
import pytest_mypy
def _patched_runtest(*args, **kwargs):
raise Exception('{message}')
pytest_mypy.MypyItem.runtest = _patched_runtest
'''.format(message=message))
result = testdir.runpytest_subprocess()
result.assert_outcomes()
result = testdir.runpytest_subprocess('--mypy')
result.assert_outcomes(failed=1)
result.stdout.fnmatch_lines(['*' + message])
assert result.ret != 0
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ deps =
mypy0.670: mypy == 0.670
mypy0.700: mypy == 0.700
mypy0.701: mypy == 0.701

pytest-cov ~= 2.5.1
pytest-randomly ~= 2.1.1
commands = py.test {posargs:tests}
commands = py.test --cov pytest_mypy --cov-fail-under 100 --cov-report term-missing {posargs}

[testenv:flake8]
skip_install = true
Expand Down

0 comments on commit 89d5e10

Please sign in to comment.