Reputation: 41
First time posting here, and I've tried to search these past 2 days for a solution to my problem with xdist. When I try to run with n=2 or anything higher, I sometimes (I say sometimes because it works randomly) get an error along the lines of
Different tests were collected between gw1 and gw0. The difference is:
--- gw1
+++ gw0
@@ -1,2 +1,2 @@
+test_Sign_Up.py::test_sign_up[chrome] test_Sign_Up.py::test_sign_up[firefox]
-test_Sign_Up.py::test_sign_up[chrome]
Apologies if this is something simple to fix, but after looking at so many other posts I personally felt that I did not find my answer. If more info is needed then please let me know and I'll try to get back to it as quickly as possible! Thank you!
Edit: Setup
Python 3.5.3
Pytest 3.1.2
Xdist 1.17.1
Upvotes: 4
Views: 4751
Reputation: 1562
A little background to understand how pytest-xdist works
Each worker performs a standard collection and sends the collected test ids (in order) back to the master node. The master node ensures every worker collected the same number of tests and in the same order because the scheduler will from that point on send just the test indexes (not the entire node id) to each worker to tell them which test to execute. That's why the collection must be the same across all workers.
To overcome the issue, make sure the test case parameters do not depend on the process and are in sorted order.
Upvotes: 2
Reputation: 2233
If using the recently released pytest 3.2 does not fix your error, try seeding the the python interpreter's hash with a fixed number to get a stable sorting for structures that rely on hashing:
PYTHONHASHSEED=0 pytest -n 2
Upvotes: 5