|  | 
| 6 | 6 | import pexpect | 
| 7 | 7 | import pytest | 
| 8 | 8 | 
 | 
|  | 9 | +import pytest_mypy | 
|  | 10 | + | 
| 9 | 11 | 
 | 
| 10 | 12 | MYPY_VERSION = Version(mypy.version.__version__) | 
| 11 | 13 | PYTEST_VERSION = Version(pytest.__version__) | 
| @@ -554,3 +556,47 @@ def test_mypy_item_collect(request): | 
| 554 | 556 |     mypy_status_check = 1 | 
| 555 | 557 |     result.assert_outcomes(passed=test_count + mypy_file_checks + mypy_status_check) | 
| 556 | 558 |     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) | 
0 commit comments