Skip to content

Commit 09e4746

Browse files
committed
Add test_looponfail
1 parent cd459a4 commit 09e4746

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

tests/test_pytest_mypy.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import signal
2+
import textwrap
3+
14
import pytest
25

36

@@ -269,3 +272,87 @@ def pyfunc(x):
269272
'1: error: Function is missing a type annotation',
270273
])
271274
assert result.ret != 0
275+
276+
277+
def test_looponfail(testdir):
278+
"""Ensure that the plugin works with --looponfail."""
279+
280+
pass_source = textwrap.dedent(
281+
"""\
282+
def pyfunc(x: int) -> int:
283+
return x * 2
284+
""",
285+
)
286+
fail_source = textwrap.dedent(
287+
"""\
288+
def pyfunc(x: int) -> str:
289+
return x * 2
290+
""",
291+
)
292+
pyfile = testdir.makepyfile(fail_source)
293+
looponfailroot = testdir.mkdir("looponfailroot")
294+
looponfailroot_pyfile = looponfailroot.join(pyfile.basename)
295+
pyfile.move(looponfailroot_pyfile)
296+
pyfile = looponfailroot_pyfile
297+
testdir.makeini(
298+
textwrap.dedent(
299+
"""\
300+
[pytest]
301+
looponfailroots = {looponfailroots}
302+
""".format(
303+
looponfailroots=looponfailroot,
304+
),
305+
),
306+
)
307+
308+
child = testdir.spawn_pytest(
309+
"--mypy --looponfail " + str(pyfile),
310+
expect_timeout=30.0,
311+
)
312+
313+
def _expect_session():
314+
child.expect("==== test session starts ====")
315+
316+
def _expect_failure():
317+
_expect_session()
318+
child.expect("==== FAILURES ====")
319+
child.expect(pyfile.basename + " ____")
320+
child.expect("2: error: Incompatible return value")
321+
# These only show with mypy>=0.730:
322+
# child.expect("==== mypy ====")
323+
# child.expect("Found 1 error in 1 file (checked 1 source file)")
324+
child.expect("2 failed")
325+
child.expect("#### LOOPONFAILING ####")
326+
_expect_waiting()
327+
328+
def _expect_waiting():
329+
child.expect("#### waiting for changes ####")
330+
child.expect("Watching")
331+
332+
def _fix():
333+
pyfile.write(pass_source)
334+
_expect_changed()
335+
_expect_success()
336+
337+
def _expect_changed():
338+
child.expect("MODIFIED " + str(pyfile))
339+
340+
def _expect_success():
341+
for _ in range(2):
342+
_expect_session()
343+
# These only show with mypy>=0.730:
344+
# child.expect("==== mypy ====")
345+
# child.expect("Success: no issues found in 1 source file")
346+
child.expect("2 passed")
347+
_expect_waiting()
348+
349+
def _break():
350+
pyfile.write(fail_source)
351+
_expect_changed()
352+
_expect_failure()
353+
354+
_expect_failure()
355+
_fix()
356+
_break()
357+
_fix()
358+
child.kill(signal.SIGTERM)

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ deps =
132132
mypy0.79: mypy >= 0.790, < 0.800
133133
mypy0.7x: mypy >= 0.700, < 0.800
134134

135+
pexpect ~= 4.8.0
136+
135137
commands = py.test -p no:mypy --cov pytest_mypy --cov-fail-under 100 --cov-report term-missing {posargs:-n auto} tests
136138

137139
[testenv:publish]

0 commit comments

Comments
 (0)