Skip to content

Commit 7151ad8

Browse files
committed
Enable branch code coverage
1 parent 82c41fb commit 7151ad8

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

tests/test_pytest_mypy.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import pexpect
77
import pytest
88

9+
import pytest_mypy
10+
911

1012
MYPY_VERSION = Version(mypy.version.__version__)
1113
PYTEST_VERSION = Version(pytest.__version__)
@@ -554,3 +556,47 @@ def test_mypy_item_collect(request):
554556
mypy_status_check = 1
555557
result.assert_outcomes(passed=test_count + mypy_file_checks + mypy_status_check)
556558
assert result.ret == 0
559+
560+
561+
def test_mypy_results_from_mypy_with_opts():
562+
"""MypyResults.from_mypy respects passed options."""
563+
mypy_results = pytest_mypy.MypyResults.from_mypy([], opts=["--version"])
564+
assert mypy_results.status == 0
565+
assert mypy_results.abspath_errors == {}
566+
assert str(MYPY_VERSION) in mypy_results.stdout
567+
568+
569+
def test_mypy_no_output(testdir, xdist_args):
570+
"""No terminal summary is shown if there is no output from mypy."""
571+
# Pytest didn't add type annotations until 6.0.
572+
type_ignore = "# type: ignore" if PYTEST_VERSION < Version("6.0") else ""
573+
testdir.makepyfile(
574+
conftest=f"""
575+
import tempfile
576+
577+
import pytest {type_ignore}
578+
579+
@pytest.hookimpl(hookwrapper=True)
580+
def pytest_terminal_summary(config):
581+
pytest_mypy = config.pluginmanager.getplugin("mypy")
582+
with open(config._mypy_results_path, mode="r") as results_f:
583+
results = pytest_mypy.MypyResults.load(results_f)
584+
with open(config._mypy_results_path, mode="w") as results_f:
585+
pytest_mypy.MypyResults(
586+
opts=results.opts,
587+
stdout=results.stdout,
588+
stderr="",
589+
status=results.status,
590+
abspath_errors=results.abspath_errors,
591+
unmatched_stdout="",
592+
).dump(results_f)
593+
yield
594+
""",
595+
)
596+
result = testdir.runpytest_subprocess("--mypy", *xdist_args)
597+
mypy_file_checks = 1
598+
mypy_status_check = 1
599+
mypy_checks = mypy_file_checks + mypy_status_check
600+
result.assert_outcomes(passed=mypy_checks)
601+
assert result.ret == 0
602+
assert "= mypy =" not in str(result.stdout)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ deps =
4242
pytest-randomly ~= 3.4
4343
pytest-xdist ~= 1.34
4444

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

4747
[pytest]
4848
testpaths = tests

0 commit comments

Comments
 (0)