Skip to content

Commit f1aed2a

Browse files
committed
Use pytest.ExitCode in tests
1 parent 6afe15e commit f1aed2a

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

tests/test_pytest_mypy.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6465
def 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

9596
def 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

116118
def 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

137139
def 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

171173
def 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

219221
def 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

249252
def 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

300303
def 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

358361
def 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

387390
def 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

407410
def 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"])
@@ -558,7 +561,7 @@ def test_mypy_item_collect(request):
558561
mypy_file_checks = 1
559562
mypy_status_check = 1
560563
result.assert_outcomes(passed=test_count + mypy_file_checks + mypy_status_check)
561-
assert result.ret == 0
564+
assert result.ret == pytest.ExitCode.OK
562565

563566

564567
def test_mypy_results_from_mypy_with_opts():
@@ -610,5 +613,5 @@ def pytest_terminal_summary(config):
610613
mypy_status_check = 1
611614
mypy_checks = mypy_file_checks + mypy_status_check
612615
result.assert_outcomes(passed=mypy_checks)
613-
assert result.ret == 0
616+
assert result.ret == pytest.ExitCode.OK
614617
assert f"= {pytest_mypy.terminal_summary_title} =" not in str(result.stdout)

0 commit comments

Comments
 (0)