1

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
    Does this answer your question? [How to run pytest tests in parallel?](https://stackoverflow.com/questions/45733763/how-to-run-pytest-tests-in-parallel) – buhtz Jun 19 '23 at 11:20

1 Answers1

1

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
Michael Mintz
  • 9,007
  • 6
  • 31
  • 48