Added known limitation section to the docs (#796)
Co-authored-by: Josef <sorry.i-keep@it.private> Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
This commit is contained in:
1
changelog/796.doc.rst
Normal file
1
changelog/796.doc.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Added known limitations section to documentation.
|
||||||
@@ -60,4 +60,5 @@ Features
|
|||||||
crash
|
crash
|
||||||
how-to
|
how-to
|
||||||
how-it-works
|
how-it-works
|
||||||
|
known-limitations
|
||||||
changelog
|
changelog
|
||||||
|
|||||||
52
docs/known-limitations.rst
Normal file
52
docs/known-limitations.rst
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
Known limitations
|
||||||
|
=================
|
||||||
|
|
||||||
|
pytest-xdist has some limitations that may be supported in pytest but can't be supported in pytest-xdist.
|
||||||
|
|
||||||
|
Order and amount of test must be consistent
|
||||||
|
-------------------------------------------
|
||||||
|
|
||||||
|
Is is not possible to have tests that differ in order or their amount across workers.
|
||||||
|
|
||||||
|
This is especially true with ``pytest.mark.parametrize``, when values are produced with sets or other unordered iterables/generators.
|
||||||
|
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("param", {"a","b"})
|
||||||
|
def test_pytest_parametrize_unordered(param):
|
||||||
|
pass
|
||||||
|
|
||||||
|
In the example above, the fact that ``set`` are not necessarily ordered can cause different workers
|
||||||
|
to collect tests in different order, which will throw an error.
|
||||||
|
|
||||||
|
Workarounds
|
||||||
|
~~~~~~~~~~~
|
||||||
|
|
||||||
|
A solution to this is to guarantee that the parametrized values have the same order.
|
||||||
|
|
||||||
|
Some solutions:
|
||||||
|
|
||||||
|
* Convert your sequence to a ``list``.
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("param", ["a", "b"])
|
||||||
|
def test_pytest_parametrize_unordered(param):
|
||||||
|
pass
|
||||||
|
|
||||||
|
* Sort your sequence, guaranteeing order.
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("param", sorted({"a", "b"}))
|
||||||
|
def test_pytest_parametrize_unordered(param):
|
||||||
|
pass
|
||||||
@@ -14,7 +14,8 @@ def report_collection_diff(from_collection, to_collection, from_id, to_id):
|
|||||||
error_message = (
|
error_message = (
|
||||||
"Different tests were collected between {from_id} and {to_id}. "
|
"Different tests were collected between {from_id} and {to_id}. "
|
||||||
"The difference is:\n"
|
"The difference is:\n"
|
||||||
"{diff}"
|
"{diff}\n"
|
||||||
|
"To see why this happens see Known limitations in documentation"
|
||||||
).format(from_id=from_id, to_id=to_id, diff="\n".join(diff))
|
).format(from_id=from_id, to_id=to_id, diff="\n".join(diff))
|
||||||
msg = "\n".join(x.rstrip() for x in error_message.split("\n"))
|
msg = "\n".join(x.rstrip() for x in error_message.split("\n"))
|
||||||
return msg
|
return msg
|
||||||
|
|||||||
@@ -290,7 +290,8 @@ def test_report_collection_diff_different() -> None:
|
|||||||
" bbb\n"
|
" bbb\n"
|
||||||
"+XXX\n"
|
"+XXX\n"
|
||||||
" ccc\n"
|
" ccc\n"
|
||||||
"-YYY"
|
"-YYY\n"
|
||||||
|
"To see why this happens see Known limitations in documentation"
|
||||||
)
|
)
|
||||||
|
|
||||||
msg = report_collection_diff(from_collection, to_collection, "1", "2")
|
msg = report_collection_diff(from_collection, to_collection, "1", "2")
|
||||||
|
|||||||
Reference in New Issue
Block a user