Skip to content

Commit 6113277

Browse files
07pepaJosefnicoddemus
authored
Added known limitation section to the docs (#796)
Co-authored-by: Josef <[email protected]> Co-authored-by: Bruno Oliveira <[email protected]>
1 parent 8616ff3 commit 6113277

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed

changelog/796.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added known limitations section to documentation.

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ Features
6060
crash
6161
how-to
6262
how-it-works
63+
known-limitations
6364
changelog

docs/known-limitations.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Known limitations
2+
=================
3+
4+
pytest-xdist has some limitations that may be supported in pytest but can't be supported in pytest-xdist.
5+
6+
Order and amount of test must be consistent
7+
-------------------------------------------
8+
9+
Is is not possible to have tests that differ in order or their amount across workers.
10+
11+
This is especially true with ``pytest.mark.parametrize``, when values are produced with sets or other unordered iterables/generators.
12+
13+
14+
Example:
15+
16+
.. code-block:: python
17+
18+
import pytest
19+
20+
@pytest.mark.parametrize("param", {"a","b"})
21+
def test_pytest_parametrize_unordered(param):
22+
pass
23+
24+
In the example above, the fact that ``set`` are not necessarily ordered can cause different workers
25+
to collect tests in different order, which will throw an error.
26+
27+
Workarounds
28+
~~~~~~~~~~~
29+
30+
A solution to this is to guarantee that the parametrized values have the same order.
31+
32+
Some solutions:
33+
34+
* Convert your sequence to a ``list``.
35+
36+
.. code-block:: python
37+
38+
import pytest
39+
40+
@pytest.mark.parametrize("param", ["a", "b"])
41+
def test_pytest_parametrize_unordered(param):
42+
pass
43+
44+
* Sort your sequence, guaranteeing order.
45+
46+
.. code-block:: python
47+
48+
import pytest
49+
50+
@pytest.mark.parametrize("param", sorted({"a", "b"}))
51+
def test_pytest_parametrize_unordered(param):
52+
pass

src/xdist/report.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def report_collection_diff(from_collection, to_collection, from_id, to_id):
1414
error_message = (
1515
"Different tests were collected between {from_id} and {to_id}. "
1616
"The difference is:\n"
17-
"{diff}"
17+
"{diff}\n"
18+
"To see why this happens see Known limitations in documentation"
1819
).format(from_id=from_id, to_id=to_id, diff="\n".join(diff))
1920
msg = "\n".join(x.rstrip() for x in error_message.split("\n"))
2021
return msg

testing/test_dsession.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ def test_report_collection_diff_different() -> None:
290290
" bbb\n"
291291
"+XXX\n"
292292
" ccc\n"
293-
"-YYY"
293+
"-YYY\n"
294+
"To see why this happens see Known limitations in documentation"
294295
)
295296

296297
msg = report_collection_diff(from_collection, to_collection, "1", "2")

0 commit comments

Comments
 (0)