Skip to content
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

Require 100% code coverage #38

Merged
merged 2 commits into from
Jun 23, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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