pytest run tests parallel

匆匆过客 提交于 2019-12-03 09:36:28

You want pytest-xdist. I think Qxf2 explains it quite well: Qxf2 on Pytest-Xdist

Their Linux command-line is slightly too verbose for my tastes though; I use:

pytest -n <NUM>

where <NUM> is the number of parallel workers.

pytest-xdist is a great solution for most cases, but integration tests are special. After sending a request to a remote server, another test can start on a new thread instead of waiting for a response. This is concurrent testing instead of parallel. Concurrency allows many more tests at once with much less memory and processing overhead.

I wrote the pytest-parallel plugin [py3.6+] to enable parallel and concurrent testing. Here's how to run your integration tests concurrently:

pytest --tests-per-worker auto

pytest-xdist didn't work for me, because my tests were waiting 99.9999999% of the time for glue jobs from AWS to finish, and I was using a CodeBuild environment with 2 cores, so I could only run 2 tests at a time.

@kevelend's approach worked for me.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!