@@ -53,12 +53,13 @@ def pyfunc(x: int) -> int:
5353 )
5454 result = testdir .runpytest_subprocess (* xdist_args )
5555 result .assert_outcomes ()
56+ assert result .ret == pytest .ExitCode .NO_TESTS_COLLECTED
5657 result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
5758 mypy_file_checks = pyfile_count
5859 mypy_status_check = 1
5960 mypy_checks = mypy_file_checks + mypy_status_check
6061 result .assert_outcomes (passed = mypy_checks )
61- assert result .ret == 0
62+ assert result .ret == pytest . ExitCode . OK
6263
6364
6465def test_mypy_pyi (testdir , xdist_args ):
@@ -89,7 +90,7 @@ def pyfunc(x: int) -> int: ...
8990 mypy_status_check = 1
9091 mypy_checks = mypy_file_checks + mypy_status_check
9192 result .assert_outcomes (passed = mypy_checks )
92- assert result .ret == 0
93+ assert result .ret == pytest . ExitCode . OK
9394
9495
9596def test_mypy_error (testdir , xdist_args ):
@@ -103,14 +104,15 @@ def pyfunc(x: int) -> str:
103104 result = testdir .runpytest_subprocess (* xdist_args )
104105 result .assert_outcomes ()
105106 assert "_mypy_results_path" not in result .stderr .str ()
107+ assert result .ret == pytest .ExitCode .NO_TESTS_COLLECTED
106108 result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
107109 mypy_file_checks = 1
108110 mypy_status_check = 1
109111 mypy_checks = mypy_file_checks + mypy_status_check
110112 result .assert_outcomes (failed = mypy_checks )
111113 result .stdout .fnmatch_lines (["2: error: Incompatible return value*" ])
112- assert result .ret != 0
113114 assert "_mypy_results_path" not in result .stderr .str ()
115+ assert result .ret == pytest .ExitCode .TESTS_FAILED
114116
115117
116118def test_mypy_annotation_unchecked (testdir , xdist_args , tmp_path , monkeypatch ):
@@ -131,7 +133,7 @@ def pyfunc(x):
131133 outcomes = {"passed" : mypy_checks }
132134 result .assert_outcomes (** outcomes )
133135 result .stdout .fnmatch_lines (["*MypyWarning*" ])
134- assert result .ret == 0
136+ assert result .ret == pytest . ExitCode . OK
135137
136138
137139def test_mypy_ignore_missings_imports (testdir , xdist_args ):
@@ -162,10 +164,10 @@ def test_mypy_ignore_missings_imports(testdir, xdist_args):
162164 ),
163165 ],
164166 )
165- assert result .ret != 0
167+ assert result .ret == pytest . ExitCode . TESTS_FAILED
166168 result = testdir .runpytest_subprocess ("--mypy-ignore-missing-imports" , * xdist_args )
167169 result .assert_outcomes (passed = mypy_checks )
168- assert result .ret == 0
170+ assert result .ret == pytest . ExitCode . OK
169171
170172
171173def test_mypy_config_file (testdir , xdist_args ):
@@ -181,7 +183,7 @@ def pyfunc(x):
181183 mypy_status_check = 1
182184 mypy_checks = mypy_file_checks + mypy_status_check
183185 result .assert_outcomes (passed = mypy_checks )
184- assert result .ret == 0
186+ assert result .ret == pytest . ExitCode . OK
185187 mypy_config_file = testdir .makeini (
186188 """
187189 [mypy]
@@ -210,10 +212,10 @@ def test_fails():
210212 mypy_status_check = 1
211213 mypy_checks = mypy_file_checks + mypy_status_check
212214 result .assert_outcomes (failed = test_count , passed = mypy_checks )
213- assert result .ret != 0
215+ assert result .ret == pytest . ExitCode . TESTS_FAILED
214216 result = testdir .runpytest_subprocess ("--mypy" , "-m" , "mypy" , * xdist_args )
215217 result .assert_outcomes (passed = mypy_checks )
216- assert result .ret == 0
218+ assert result .ret == pytest . ExitCode . OK
217219
218220
219221def test_non_mypy_error (testdir , xdist_args ):
@@ -235,6 +237,7 @@ def runtest(self):
235237 )
236238 result = testdir .runpytest_subprocess (* xdist_args )
237239 result .assert_outcomes ()
240+ assert result .ret == pytest .ExitCode .NO_TESTS_COLLECTED
238241 result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
239242 mypy_file_checks = 1 # conftest.py
240243 mypy_status_check = 1
@@ -243,7 +246,7 @@ def runtest(self):
243246 passed = mypy_status_check , # conftest.py has no type errors.
244247 )
245248 result .stdout .fnmatch_lines (["*" + message ])
246- assert result .ret != 0
249+ assert result .ret == pytest . ExitCode . TESTS_FAILED
247250
248251
249252def test_mypy_stderr (testdir , xdist_args ):
@@ -294,7 +297,7 @@ def pytest_configure(config):
294297 """ ,
295298 )
296299 result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
297- assert result .ret == 0
300+ assert result .ret == pytest . ExitCode . OK
298301
299302
300303def test_api_nodeid_name (testdir , xdist_args ):
@@ -311,7 +314,7 @@ def pytest_configure(config):
311314 )
312315 result = testdir .runpytest_subprocess ("--mypy" , "--verbose" , * xdist_args )
313316 result .stdout .fnmatch_lines (["*conftest.py::" + nodeid_name + "*" ])
314- assert result .ret == 0
317+ assert result .ret == pytest . ExitCode . OK
315318
316319
317320@pytest .mark .xfail (
@@ -352,7 +355,7 @@ def pyfunc(x: int) -> str:
352355 mypy_file_checks = 1
353356 mypy_status_check = 1
354357 result .assert_outcomes (passed = mypy_file_checks , failed = mypy_status_check )
355- assert result .ret != 0
358+ assert result .ret == pytest . ExitCode . TESTS_FAILED
356359
357360
358361def test_api_error_formatter (testdir , xdist_args ):
@@ -381,7 +384,7 @@ def pytest_configure(config):
381384 )
382385 result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
383386 result .stdout .fnmatch_lines (["*/bad.py:2: error: Incompatible return value*" ])
384- assert result .ret != 0
387+ assert result .ret == pytest . ExitCode . TESTS_FAILED
385388
386389
387390def test_pyproject_toml (testdir , xdist_args ):
@@ -401,7 +404,7 @@ def pyfunc(x):
401404 )
402405 result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
403406 result .stdout .fnmatch_lines (["1: error: Function is missing a type annotation*" ])
404- assert result .ret != 0
407+ assert result .ret == pytest . ExitCode . TESTS_FAILED
405408
406409
407410def test_setup_cfg (testdir , xdist_args ):
@@ -421,7 +424,7 @@ def pyfunc(x):
421424 )
422425 result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
423426 result .stdout .fnmatch_lines (["1: error: Function is missing a type annotation*" ])
424- assert result .ret != 0
427+ assert result .ret == pytest . ExitCode . TESTS_FAILED
425428
426429
427430@pytest .mark .parametrize ("module_name" , ["__init__" , "test_demo" ])
@@ -537,30 +540,6 @@ def _break():
537540 child .kill (signal .SIGTERM )
538541
539542
540- def test_mypy_item_collect (testdir , xdist_args ):
541- """Ensure coverage for a 3.10<=pytest<6.0 workaround."""
542- testdir .makepyfile (
543- """
544- def test_mypy_item_collect(request):
545- plugin = request.config.pluginmanager.getplugin("mypy")
546- mypy_items = [
547- item
548- for item in request.session.items
549- if isinstance(item, plugin.MypyItem)
550- ]
551- assert mypy_items
552- for mypy_item in mypy_items:
553- assert all(item is mypy_item for item in mypy_item.collect())
554- """ ,
555- )
556- result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
557- test_count = 1
558- mypy_file_checks = 1
559- mypy_status_check = 1
560- result .assert_outcomes (passed = test_count + mypy_file_checks + mypy_status_check )
561- assert result .ret == 0
562-
563-
564543def test_mypy_results_from_mypy_with_opts ():
565544 """MypyResults.from_mypy respects passed options."""
566545 mypy_results = pytest_mypy .MypyResults .from_mypy ([], opts = ["--version" ])
@@ -610,5 +589,5 @@ def pytest_terminal_summary(config):
610589 mypy_status_check = 1
611590 mypy_checks = mypy_file_checks + mypy_status_check
612591 result .assert_outcomes (passed = mypy_checks )
613- assert result .ret == 0
592+ assert result .ret == pytest . ExitCode . OK
614593 assert f"= { pytest_mypy .terminal_summary_title } =" not in str (result .stdout )
0 commit comments