lk-geimfari / mimesis

Mimesis is a robust data generator for Python that can produce a wide range of fake data in multiple languages.
https://mimesis.name
MIT License
4.39k stars 330 forks source link

Optimize tests timings #300

Closed sobolevn closed 6 years ago

sobolevn commented 6 years ago

Right now tests take more than 7 minutes. https://github.com/lk-geimfari/mimesis/issues/263#issuecomment-347634658

What do I suggest:

  1. profiling
  2. using several threads with pytest-xdist
  3. optimisation
lk-geimfari commented 6 years ago

So, on disabled flag --verbose usual testing took ~25 second (without pytest-xdist) and I thinks that is not a bad result.

As for mypy, then:

without pytest-xdist:

py.test --mypy mimesis/
================================================================= test session starts =================================================================
platform linux -- Python 3.5.2, pytest-3.2.3, py-1.4.34, pluggy-0.4.0
rootdir: /home/likid/Development/open_source/mimesis, inifile: pytest.ini
plugins: forked-0.2, xdist-1.20.1, cov-2.5.1, mypy-0.3.0, flake8-0.8.1, mock-1.6.3
collected 101 items 
============================================================ 101 passed in 399.73 seconds =============================================================

on the single core:

py.test -n 1 --mypy mimesis/
================================================================= test session starts =================================================================
platform linux -- Python 3.5.2, pytest-3.2.3, py-1.4.34, pluggy-0.4.0
rootdir: /home/likid/Development/open_source/mimesis, inifile: pytest.ini
plugins: forked-0.2, xdist-1.20.1, cov-2.5.1, mypy-0.3.0, flake8-0.8.1, mock-1.6.3
gw0 [101]
scheduling tests via LoadScheduling
.....................................................................................................
============================================================ 101 passed in 356.98 seconds =============================================================

on the 2 cores:

py.test -n 2 --mypy mimesis/
================================================================= test session starts =================================================================
platform linux -- Python 3.5.2, pytest-3.2.3, py-1.4.34, pluggy-0.4.0
rootdir: /home/likid/Development/open_source/mimesis, inifile: pytest.ini
plugins: forked-0.2, xdist-1.20.1, cov-2.5.1, mypy-0.3.0, flake8-0.8.1, mock-1.6.3
gw0 [101] / gw1 [101]
scheduling tests via LoadScheduling
.....................................................................................................
============================================================ 101 passed in 232.25 seconds =============================================================
sobolevn commented 6 years ago

Oh, mypy takes so much time? From 25 seconds to almost 400 seconds?

How many CPU cores do you have? I usually set -n to 4 to leverage all my cores.

lk-geimfari commented 6 years ago

@sobolevn On using with pytest-mypy, on using just mypy it works very fast. Less than 10 seconds.

lk-geimfari commented 6 years ago

@sobolevn I have used flag -n auto and it's detected 4 cores automatically.

sobolevn commented 6 years ago

@lk-geimfari did not know about auto. Could you create a PR with this fix for https://github.com/wemake-services/wemake-django-template please?

So, why won't we just run them separately? mypy first, then pytest?

lk-geimfari commented 6 years ago

@sobolevn I think so too. I'll fix it. What worries me, since Travis CI understands that the tests were successful? If we will use just mypy, without pytest, then how Travis understand that type check is passed?

lk-geimfari commented 6 years ago

@sobolevn Do you mean auto for wemake-django-template? Do you use pytest-xdist, because I can't find it in Pipfile.

lk-geimfari commented 6 years ago

So, it's done. We'll use just mypy, not pytest-mypy. It works fine!

lk-geimfari commented 6 years ago

Fixed in #299

sobolevn commented 6 years ago

Please, don't forget to fix https://github.com/wemake-services/wemake-django-template/blob/master/%7B%7Bcookiecutter.project_name%7D%7D/setup.cfg#L37 Thanks!

lk-geimfari commented 6 years ago

@sobolevn I have created PR. Seems it works fine, but the first attempt was failed if you look at logs of Travis.

lk-geimfari commented 6 years ago

@sobolevn Also Travis provides CPU with 2 cores, not 4.