Is there a way to run pytests using xdist by file(s)?

775 views Asked by At

I am trying to run 2 test files using xdist with 2 gateways (-n=2). Each test file contains tests which are user permission specific. While running the test with pytest and pytest-xdist, I noticed some of the test fail randomly. It is happening because some of the tests from file1 getting executed by a different gw. So, if [gw0] was running most of the tests from file0, sometimes, [gw0] also executes some tests from file1 which causes the failure.

I am trying to find out if there is a way I can force/ask xdist to execute a specific file or perhaps if there is a way to assign a file to a gw?

pytest test_*.py -n=2 -s -v

also tried:

pytest test_*.py -n=2 -s -v --dist=loadfile

1

There are 1 answers

1
Rafael C. On

Assuming your file for running parallel tests is correctly distributed (properly receiving PYTEST_XDIST_WORKER and PYTEST_XDIST_WORKER_COUNT environment variables), you only need to run:

pytest test_*.py --tx '2*popen' --dist=loadfile --dist=each