@@ -457,17 +457,6 @@ ones. This means that relative ordering always takes preference:
457
457
In this case, ``test_second `` will be executed before ``test_first ``,
458
458
regardless of the ordinal markers.
459
459
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
-
471
460
Configuration
472
461
=============
473
462
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
832
821
.. note ::
833
822
This option will not work together well with the sparse ordering option.
834
823
824
+ .. _indulgent-ordering :
825
+
835
826
``--indulgent-ordering ``
836
827
------------------------
837
828
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.
1000
991
This feature is considered experimental. It may not handle all cases of
1001
992
defined dependencies. Please write an issue if you find any problems.
1002
993
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
+
1005
1063
1006
1064
Usage with pytest-xdist
1007
1065
-----------------------
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
1014
1073
`this issue <https://github.com/ftobia/pytest-ordering/issues/36 >`__).
1015
1074
1016
1075
.. toctree ::
1017
1076
:maxdepth: 2
1018
-
1019
- .. _markers : https://pytest.org/latest/mark.html
0 commit comments