title: Run python tests in parallel
body: <p>I tried to run my tests using pytest with <a href="https://pytest.org/latest/xdist.html" rel="nofollow">xdist</a> in order to speed up my tests (that are very slow since most of them involve database transactions with SQLAlchemy). I launched them with:</p>
  
  <p><code>py.test -n 4</code></p>
  
  <p>(since my macbook pro has 4 cores)</p>
  
  <p>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?</p>
  
  <p>ps. I'm using Python 3.5.1 and all my tests inherit from <code>unittest.TestCase</code></p>