@@ -561,3 +561,59 @@ def test_mypy_no_status_check(testdir, xdist_args):
561
561
result = testdir .runpytest_subprocess ("--mypy-no-status-check" , * xdist_args )
562
562
result .assert_outcomes (passed = mypy_file_checks )
563
563
assert result .ret == pytest .ExitCode .OK
564
+
565
+
566
+ def test_mypy_xfail_passes (testdir , xdist_args ):
567
+ """Verify that --mypy-xfail passes passes."""
568
+ testdir .makepyfile (thon = "one: int = 1" )
569
+ result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
570
+ mypy_file_checks = 1
571
+ mypy_status_check = 1
572
+ result .assert_outcomes (passed = mypy_file_checks + mypy_status_check )
573
+ assert result .ret == pytest .ExitCode .OK
574
+ result = testdir .runpytest_subprocess ("--mypy-xfail" , * xdist_args )
575
+ result .assert_outcomes (passed = mypy_file_checks + mypy_status_check )
576
+ assert result .ret == pytest .ExitCode .OK
577
+
578
+
579
+ def test_mypy_xfail_xfails (testdir , xdist_args ):
580
+ """Verify that --mypy-xfail xfails failures."""
581
+ testdir .makepyfile (thon = "one: str = 1" )
582
+ result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
583
+ mypy_file_checks = 1
584
+ mypy_status_check = 1
585
+ result .assert_outcomes (failed = mypy_file_checks + mypy_status_check )
586
+ assert result .ret == pytest .ExitCode .TESTS_FAILED
587
+ result = testdir .runpytest_subprocess ("--mypy-xfail" , * xdist_args )
588
+ result .assert_outcomes (xfailed = mypy_file_checks + mypy_status_check )
589
+ assert result .ret == pytest .ExitCode .OK
590
+
591
+
592
+ def test_mypy_xfail_reports_stdout (testdir , xdist_args ):
593
+ """Verify that --mypy-xfail reports stdout from mypy."""
594
+ stdout = "a distinct string on stdout"
595
+ testdir .makepyfile (
596
+ conftest = f"""
597
+ import pytest
598
+
599
+ @pytest.hookimpl(trylast=True)
600
+ def pytest_configure(config):
601
+ pytest_mypy = config.pluginmanager.getplugin("mypy")
602
+ mypy_config_stash = config.stash[pytest_mypy.stash_key["config"]]
603
+ with open(mypy_config_stash.mypy_results_path, mode="w") as results_f:
604
+ pytest_mypy.MypyResults(
605
+ opts=[],
606
+ stdout="{ stdout } ",
607
+ stderr="",
608
+ status=0,
609
+ abspath_errors={{}},
610
+ unmatched_stdout="",
611
+ ).dump(results_f)
612
+ """ ,
613
+ )
614
+ result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
615
+ assert result .ret == pytest .ExitCode .OK
616
+ assert stdout not in result .stdout .str ()
617
+ result = testdir .runpytest_subprocess ("--mypy-xfail" , * xdist_args )
618
+ assert result .ret == pytest .ExitCode .OK
619
+ assert stdout in result .stdout .str ()
0 commit comments