realpython / pytest-mypy

Mypy static type checker plugin for Pytest
https://pypi.org/project/pytest-mypy/
MIT License
247 stars 32 forks source link

Slow #4

Closed uolot closed 6 years ago

uolot commented 7 years ago

It looks like a nice and useful plugin, but unfortunately is terribly slow:

$ time (mypy . ; pytest)
real    0m5.491s
user    0m4.944s
sys     0m0.304s

$ time (find . -name \*.py | xargs mypy ; pytest)
real    0m5.322s
user    0m4.752s
sys     0m0.292s

$ time pytest --mypy
real    0m44.829s
user    0m42.872s
sys     0m0.488s
ingolemo commented 7 years ago

Try passing the --incremental flag to mypy. It's experimental, but it should provide a good speed up.

Maybe the plugin should add it by default?

chdsbd commented 6 years ago

@dbader I think it would be useful to add a warning to the README about this (I can make the change if you want).

In my case, my tests take 5:48 when using this plugin. If I run mypy without the plugin, the total test time goes down to 0:35.

dmtucker commented 6 years ago

The way pytest-mypy runs is a lot like @uolot's second example, but with xargs -n1 mypy:

(vtes-S40RGN8u) david@kahuna:~/Projects/vtes $ time (find . -name \*.py | xargs mypy ; pytest)
...
real    0m11.797s
user    0m10.878s
sys 0m0.845s
(vtes-S40RGN8u) david@kahuna:~/Projects/vtes $ time (find . -name \*.py | xargs -n1 mypy ; pytest)
...
real    0m21.884s
user    0m20.383s
sys 0m1.215s
(vtes-S40RGN8u) david@kahuna:~/Projects/vtes $ time pytest --mypy
...
real    0m22.912s
user    0m21.448s
sys 0m1.156s

I've opened a PR that implements @ingolemo's suggestion which should help remedy this.