Skip to content

Commit

Permalink
Enable branch code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dmtucker committed Jul 15, 2023
1 parent 82c41fb commit 7151ad8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions tests/test_pytest_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import pexpect
import pytest

import pytest_mypy


MYPY_VERSION = Version(mypy.version.__version__)
PYTEST_VERSION = Version(pytest.__version__)
Expand Down Expand Up @@ -554,3 +556,47 @@ def test_mypy_item_collect(request):
mypy_status_check = 1
result.assert_outcomes(passed=test_count + mypy_file_checks + mypy_status_check)
assert result.ret == 0


def test_mypy_results_from_mypy_with_opts():
"""MypyResults.from_mypy respects passed options."""
mypy_results = pytest_mypy.MypyResults.from_mypy([], opts=["--version"])
assert mypy_results.status == 0
assert mypy_results.abspath_errors == {}
assert str(MYPY_VERSION) in mypy_results.stdout


def test_mypy_no_output(testdir, xdist_args):
"""No terminal summary is shown if there is no output from mypy."""
# Pytest didn't add type annotations until 6.0.
type_ignore = "# type: ignore" if PYTEST_VERSION < Version("6.0") else ""
testdir.makepyfile(
conftest=f"""
import tempfile
import pytest {type_ignore}
@pytest.hookimpl(hookwrapper=True)
def pytest_terminal_summary(config):
pytest_mypy = config.pluginmanager.getplugin("mypy")
with open(config._mypy_results_path, mode="r") as results_f:
results = pytest_mypy.MypyResults.load(results_f)
with open(config._mypy_results_path, mode="w") as results_f:
pytest_mypy.MypyResults(
opts=results.opts,
stdout=results.stdout,
stderr="",
status=results.status,
abspath_errors=results.abspath_errors,
unmatched_stdout="",
).dump(results_f)
yield
""",
)
result = testdir.runpytest_subprocess("--mypy", *xdist_args)
mypy_file_checks = 1
mypy_status_check = 1
mypy_checks = mypy_file_checks + mypy_status_check
result.assert_outcomes(passed=mypy_checks)
assert result.ret == 0
assert "= mypy =" not in str(result.stdout)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ deps =
pytest-randomly ~= 3.4
pytest-xdist ~= 1.34

commands = pytest -p no:mypy {posargs:--cov pytest_mypy --cov-fail-under 100 --cov-report term-missing -n auto}
commands = pytest -p no:mypy {posargs:--cov pytest_mypy --cov-branch --cov-fail-under 100 --cov-report term-missing -n auto}

[pytest]
testpaths = tests
Expand Down

0 comments on commit 7151ad8

Please sign in to comment.