Skip to content

Conversation

TurtleOrangina
Copy link

@TurtleOrangina TurtleOrangina commented Dec 6, 2019

Resolve #72

Commit 11d6c23
from Author: David Tucker david@tucker.name @dmtucker
On 2019-06-16 21:05:55
Subject: Call mypy once and parse its output

The above commit makes it so that runtest() no longer runs any tests, instead the pytest_runtestloop is overwritten to allow to run mypy only once. When using pytest-mypy in conjunction with pytest-xdist, this leads to mypy not being invoked at all anymore: pytest-xdist overwrites the runtestloop, so pytest-mypy runtestloop is no longer executing. pytest-xdist does call runtest(), but since that does no longer run any tests mypy is not invoked (and even worse, it is claimed no error occured, since the state that mypy was never run is not recorded).

This MR is my crude attempt to fix the problem: runtest() needs to run mypy if the runtestloop did not execute. For my setup with xdist+mypy this now results in the mypy checks actually running again.

Let me know your thoughts :)

@dmtucker
Copy link
Collaborator

dmtucker commented Dec 6, 2019

Thank for reporting this AND taking a stab at a fix! 👍

I was able to devise a test that reproduces the underlying issue:

diff --git a/tests/test_pytest_mypy.py b/tests/test_pytest_mypy.py
index 45a4783..aafb3f9 100644
--- a/tests/test_pytest_mypy.py
+++ b/tests/test_pytest_mypy.py
@@ -19,7 +19,7 @@ def test_mypy_error(testdir):
     ''')
     result = testdir.runpytest_subprocess()
     result.assert_outcomes()
-    result = testdir.runpytest_subprocess('--mypy')
+    result = testdir.runpytest_subprocess('--mypy', '-n', 'auto')
     result.assert_outcomes(failed=1)
     result.stdout.fnmatch_lines([
         '2: error: Incompatible return value*',
diff --git a/tox.ini b/tox.ini
index 6615cc2..8722621 100644
--- a/tox.ini
+++ b/tox.ini
@@ -70,6 +70,7 @@ deps =
 
     pytest-cov ~= 2.5.1
     pytest-randomly ~= 2.1.1
+    pytest-xdist ~= 1.30.0
 commands = py.test --cov pytest_mypy --cov-fail-under 100 --cov-report term-missing {posargs}
 
 [testenv:flake8]

I'll try to take a closer look at this over the weekend 😊

@TurtleOrangina
Copy link
Author

Can confirm the test reproduces the issue, did you have any insights during the weekend? Anything I can do to speed things up?

Copy link
Collaborator

@dmtucker dmtucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this would work; however, it means that the plugin would revert to the pre-0.4.0 behavior of running mypy once for every MypyItem when pytest-xdist is enabled. Instead, I would like to supersede this with #73, if that's ok with you.

@TurtleOrangina
Copy link
Author

TurtleOrangina commented Feb 5, 2020 via email

@dmtucker dmtucker closed this Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider supporting pytest-xdist

2 participants