Skip to content

Commit aa76291

Browse files
committed
Add some documentation for working with other plugins
- move pytest-dependency and pytest-xdists paragraphs into that chapter - add paragraph about pytest-randomly and similar plugins
1 parent 21a1778 commit aa76291

File tree

2 files changed

+79
-23
lines changed

2 files changed

+79
-23
lines changed

docs/source/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454

5555
# General information about the project.
5656
project = u"pytest-order"
57-
copyright = u"2014, Frank Tobia"
5857

5958
# The version info for the project you"re documenting, acts as replacement for
6059
# |version| and |release|, also used in various other places throughout the
@@ -176,7 +175,7 @@
176175
html_show_sphinx = False
177176

178177
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
179-
# html_show_copyright = True
178+
html_show_copyright = False
180179

181180
# If true, an OpenSearch description file will be output, and all pages will
182181
# contain a <link> tag referring to it. The value of this option must be the

docs/source/index.rst

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -457,17 +457,6 @@ ones. This means that relative ordering always takes preference:
457457
In this case, ``test_second`` will be executed before ``test_first``,
458458
regardless of the ordinal markers.
459459

460-
Relationship with pytest-dependency
461-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
462-
The `pytest-dependency <https://pypi.org/project/pytest-dependency/>`__
463-
plugin also manages dependencies between tests (skips tests that depend
464-
on skipped or failed tests), but currently doesn't do any ordering. If you
465-
want to execute the tests in a specific order to each other, you can use
466-
``pytest-order``. If you want to skip or xfail tests dependent on other
467-
tests you can use ``pytest-dependency``. If you want to have both behaviors
468-
combined, you can use both plugins together with the
469-
option :ref:`order-dependencies`, described below.
470-
471460
Configuration
472461
=============
473462
There are a few command line options that change the behavior of the
@@ -832,6 +821,8 @@ This will also work with dependency markers if using the
832821
.. note::
833822
This option will not work together well with the sparse ordering option.
834823

824+
.. _indulgent-ordering:
825+
835826
``--indulgent-ordering``
836827
------------------------
837828
You may sometimes find that you want to suggest an ordering of tests, while
@@ -1000,20 +991,86 @@ adds ordering to the existing functionality if needed.
1000991
This feature is considered experimental. It may not handle all cases of
1001992
defined dependencies. Please write an issue if you find any problems.
1002993

1003-
Miscellaneous
1004-
=============
994+
Using pytest-order with other pytest plugins
995+
============================================
996+
997+
Relationship with pytest-dependency
998+
-----------------------------------
999+
The `pytest-dependency <https://pypi.org/project/pytest-dependency/>`__
1000+
plugin also manages dependencies between tests (skips tests that depend
1001+
on skipped or failed tests), but currently doesn't do any ordering. If you
1002+
want to execute the tests in a specific order to each other, you can use
1003+
``pytest-order``. If you want to skip or xfail tests dependent on other
1004+
tests you can use ``pytest-dependency``. If you want to have both behaviors
1005+
combined, you can use both plugins together with the
1006+
option :ref:`order-dependencies`, described above.
1007+
1008+
Using together with pytest-randomly
1009+
-----------------------------------
1010+
There is a number of other pytest plugins that change the order in which tests
1011+
are executed, the most widely known probably being
1012+
`pytest-randomly <https://pypi.org/project/pytest-randomly/>`__, which
1013+
executes tests in a random order to avoid unknown test dependencies.
1014+
``pytest-order`` should still work with these as long as it is executed
1015+
*after* the other plugins (which it should by default, except if you use
1016+
the option :ref:`indulgent-ordering`).
1017+
The marked tests still shall be ordered correctly, but the order of the
1018+
unordered tests will change, depending on the order the tests have been
1019+
after these other plugins have reordered them.
1020+
For example, if you have installed ``pytest-randomly``, and run the
1021+
following tests:
1022+
1023+
.. code:: python
1024+
1025+
import pytest
1026+
1027+
@pytest.mark.order(1)
1028+
def test_second():
1029+
assert True
1030+
1031+
def test_third():
1032+
assert True
1033+
1034+
def test_fourth():
1035+
assert True
1036+
1037+
@pytest.mark.order(0)
1038+
def test_first():
1039+
assert True
1040+
1041+
the output could either be:
1042+
1043+
::
1044+
1045+
test_randomly.py::test_first PASSED
1046+
test_randomly.py::test_second PASSED
1047+
test_randomly.py::test_third PASSED
1048+
test_randomly.py::test_fourth PASSED
1049+
1050+
or:
1051+
1052+
::
1053+
1054+
test_randomly.py::test_first PASSED
1055+
test_randomly.py::test_second PASSED
1056+
test_randomly.py::test_fourth PASSED
1057+
test_randomly.py::test_third PASSED
1058+
1059+
The same is true for relative ordering. The tests will be correctly ordered
1060+
before and after the tests as configured, but all other tests will be in an
1061+
arbitrary order.
1062+
10051063

10061064
Usage with pytest-xdist
10071065
-----------------------
1008-
The ``pytest-xdist`` plugin schedules tests unordered, and the order
1009-
configured by ``pytest-order`` will normally not be preserved. But
1010-
if we use the ``--dist=loadfile`` option, provided by ``xdist``, all tests
1011-
from one file will be run in the same thread. So, to make the two plugins work
1012-
together, we have to put each group of dependent tests in one file, and call
1013-
pytest with ``--dist=loadfile`` (this is taken from
1066+
The `pytest-xdist <https://pypi.org/project/pytest-xdist/>`__ plugin
1067+
schedules tests unordered, and the order configured by ``pytest-order``
1068+
will normally not be preserved. But if we use the ``--dist=loadfile``
1069+
option, provided by ``xdist``, all tests from one file will be run in the
1070+
same thread. So, to make the two plugins work together, we have to put
1071+
each group of dependent tests in one file, and call pytest with
1072+
``--dist=loadfile`` (this is taken from
10141073
`this issue <https://github.com/ftobia/pytest-ordering/issues/36>`__).
10151074

10161075
.. toctree::
10171076
:maxdepth: 2
1018-
1019-
.. _markers: https://pytest.org/latest/mark.html

0 commit comments

Comments
 (0)