lundi 30 mai 2016

Run python tests in parallel

I tried to run my tests using pytest with xdist in order to speed up my tests (that are very slow since most of them involve database transactions with SQLAlchemy). I launched them with:

py.test -n 4

(since my macbook pro has 4 cores)

As result, tests run in half the time previously required, but many of them fail (they pass if I run them normally). So the problem seems to be that my code is not thread safe. My question is: how can I create tests that can be safely executed in parallel, considering that my code does not explicitly makes use of threads and async code execution? Is there a rule of thumb and/or special decorators/TestCases to use? And moreover... why speed becomes 2x instead of 4x that I was expecting?

ps. I'm using Python 3.5.1 and all my tests inherit from unittest.TestCase

Aucun commentaire:

Enregistrer un commentaire