@@ -53,12 +53,13 @@ def pyfunc(x: int) -> int:
53
53
)
54
54
result = testdir .runpytest_subprocess (* xdist_args )
55
55
result .assert_outcomes ()
56
+ assert result .ret == pytest .ExitCode .NO_TESTS_COLLECTED
56
57
result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
57
58
mypy_file_checks = pyfile_count
58
59
mypy_status_check = 1
59
60
mypy_checks = mypy_file_checks + mypy_status_check
60
61
result .assert_outcomes (passed = mypy_checks )
61
- assert result .ret == 0
62
+ assert result .ret == pytest . ExitCode . OK
62
63
63
64
64
65
def test_mypy_pyi (testdir , xdist_args ):
@@ -89,7 +90,7 @@ def pyfunc(x: int) -> int: ...
89
90
mypy_status_check = 1
90
91
mypy_checks = mypy_file_checks + mypy_status_check
91
92
result .assert_outcomes (passed = mypy_checks )
92
- assert result .ret == 0
93
+ assert result .ret == pytest . ExitCode . OK
93
94
94
95
95
96
def test_mypy_error (testdir , xdist_args ):
@@ -103,14 +104,15 @@ def pyfunc(x: int) -> str:
103
104
result = testdir .runpytest_subprocess (* xdist_args )
104
105
result .assert_outcomes ()
105
106
assert "_mypy_results_path" not in result .stderr .str ()
107
+ assert result .ret == pytest .ExitCode .NO_TESTS_COLLECTED
106
108
result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
107
109
mypy_file_checks = 1
108
110
mypy_status_check = 1
109
111
mypy_checks = mypy_file_checks + mypy_status_check
110
112
result .assert_outcomes (failed = mypy_checks )
111
113
result .stdout .fnmatch_lines (["2: error: Incompatible return value*" ])
112
- assert result .ret != 0
113
114
assert "_mypy_results_path" not in result .stderr .str ()
115
+ assert result .ret == pytest .ExitCode .TESTS_FAILED
114
116
115
117
116
118
def test_mypy_annotation_unchecked (testdir , xdist_args , tmp_path , monkeypatch ):
@@ -131,7 +133,7 @@ def pyfunc(x):
131
133
outcomes = {"passed" : mypy_checks }
132
134
result .assert_outcomes (** outcomes )
133
135
result .stdout .fnmatch_lines (["*MypyWarning*" ])
134
- assert result .ret == 0
136
+ assert result .ret == pytest . ExitCode . OK
135
137
136
138
137
139
def test_mypy_ignore_missings_imports (testdir , xdist_args ):
@@ -162,10 +164,10 @@ def test_mypy_ignore_missings_imports(testdir, xdist_args):
162
164
),
163
165
],
164
166
)
165
- assert result .ret != 0
167
+ assert result .ret == pytest . ExitCode . TESTS_FAILED
166
168
result = testdir .runpytest_subprocess ("--mypy-ignore-missing-imports" , * xdist_args )
167
169
result .assert_outcomes (passed = mypy_checks )
168
- assert result .ret == 0
170
+ assert result .ret == pytest . ExitCode . OK
169
171
170
172
171
173
def test_mypy_config_file (testdir , xdist_args ):
@@ -181,7 +183,7 @@ def pyfunc(x):
181
183
mypy_status_check = 1
182
184
mypy_checks = mypy_file_checks + mypy_status_check
183
185
result .assert_outcomes (passed = mypy_checks )
184
- assert result .ret == 0
186
+ assert result .ret == pytest . ExitCode . OK
185
187
mypy_config_file = testdir .makeini (
186
188
"""
187
189
[mypy]
@@ -210,10 +212,10 @@ def test_fails():
210
212
mypy_status_check = 1
211
213
mypy_checks = mypy_file_checks + mypy_status_check
212
214
result .assert_outcomes (failed = test_count , passed = mypy_checks )
213
- assert result .ret != 0
215
+ assert result .ret == pytest . ExitCode . TESTS_FAILED
214
216
result = testdir .runpytest_subprocess ("--mypy" , "-m" , "mypy" , * xdist_args )
215
217
result .assert_outcomes (passed = mypy_checks )
216
- assert result .ret == 0
218
+ assert result .ret == pytest . ExitCode . OK
217
219
218
220
219
221
def test_non_mypy_error (testdir , xdist_args ):
@@ -235,6 +237,7 @@ def runtest(self):
235
237
)
236
238
result = testdir .runpytest_subprocess (* xdist_args )
237
239
result .assert_outcomes ()
240
+ assert result .ret == pytest .ExitCode .NO_TESTS_COLLECTED
238
241
result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
239
242
mypy_file_checks = 1 # conftest.py
240
243
mypy_status_check = 1
@@ -243,7 +246,7 @@ def runtest(self):
243
246
passed = mypy_status_check , # conftest.py has no type errors.
244
247
)
245
248
result .stdout .fnmatch_lines (["*" + message ])
246
- assert result .ret != 0
249
+ assert result .ret == pytest . ExitCode . TESTS_FAILED
247
250
248
251
249
252
def test_mypy_stderr (testdir , xdist_args ):
@@ -294,7 +297,7 @@ def pytest_configure(config):
294
297
""" ,
295
298
)
296
299
result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
297
- assert result .ret == 0
300
+ assert result .ret == pytest . ExitCode . OK
298
301
299
302
300
303
def test_api_nodeid_name (testdir , xdist_args ):
@@ -311,7 +314,7 @@ def pytest_configure(config):
311
314
)
312
315
result = testdir .runpytest_subprocess ("--mypy" , "--verbose" , * xdist_args )
313
316
result .stdout .fnmatch_lines (["*conftest.py::" + nodeid_name + "*" ])
314
- assert result .ret == 0
317
+ assert result .ret == pytest . ExitCode . OK
315
318
316
319
317
320
@pytest .mark .xfail (
@@ -352,7 +355,7 @@ def pyfunc(x: int) -> str:
352
355
mypy_file_checks = 1
353
356
mypy_status_check = 1
354
357
result .assert_outcomes (passed = mypy_file_checks , failed = mypy_status_check )
355
- assert result .ret != 0
358
+ assert result .ret == pytest . ExitCode . TESTS_FAILED
356
359
357
360
358
361
def test_api_error_formatter (testdir , xdist_args ):
@@ -381,7 +384,7 @@ def pytest_configure(config):
381
384
)
382
385
result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
383
386
result .stdout .fnmatch_lines (["*/bad.py:2: error: Incompatible return value*" ])
384
- assert result .ret != 0
387
+ assert result .ret == pytest . ExitCode . TESTS_FAILED
385
388
386
389
387
390
def test_pyproject_toml (testdir , xdist_args ):
@@ -401,7 +404,7 @@ def pyfunc(x):
401
404
)
402
405
result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
403
406
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
405
408
406
409
407
410
def test_setup_cfg (testdir , xdist_args ):
@@ -421,7 +424,7 @@ def pyfunc(x):
421
424
)
422
425
result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
423
426
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
425
428
426
429
427
430
@pytest .mark .parametrize ("module_name" , ["__init__" , "test_demo" ])
@@ -537,30 +540,6 @@ def _break():
537
540
child .kill (signal .SIGTERM )
538
541
539
542
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
-
564
543
def test_mypy_results_from_mypy_with_opts ():
565
544
"""MypyResults.from_mypy respects passed options."""
566
545
mypy_results = pytest_mypy .MypyResults .from_mypy ([], opts = ["--version" ])
@@ -610,5 +589,5 @@ def pytest_terminal_summary(config):
610
589
mypy_status_check = 1
611
590
mypy_checks = mypy_file_checks + mypy_status_check
612
591
result .assert_outcomes (passed = mypy_checks )
613
- assert result .ret == 0
592
+ assert result .ret == pytest . ExitCode . OK
614
593
assert f"= { pytest_mypy .terminal_summary_title } =" not in str (result .stdout )
0 commit comments