Run multiple pytest file parallelly

906 Views Asked by At

In my parent folder there is a subfolder tests and all pytest files are inside these. For example

..../tests/test_abc.py .../tests/test_xyz.py

There are about 8 to 10 test cases in each of the pytest files. I want to run both these files parallelly as executing one after another it's taking a lot of time, to execute 20 cases.

1

There are 1 best solutions below

0
Michael Mintz On

You specifically want to use the --dist=loadfile arg of pytest-xdist in order to split tests in parallel via file. From the documentation: Tests are grouped by their containing file. Groups are distributed to available workers as whole units. This guarantees that all tests in a file run in the same worker.

So you would first pip install pytest-xdist, and then run your tests like this:

pytest -n2 --dist=loadfile