1
- pytest-order: run your tests in order
2
- ======================================
3
- pytest-order is a pytest plugin to run your tests in any order that
4
- you specify. It provides the marker ``order ``, that defines when your tests
5
- should run in relation to each other. They can be absolute (i.e. first, or
6
- second-to-last) or relative (i.e. run this test before this other test).
1
+ Introduction
2
+ ============
3
+ ``pytest-order `` is a pytest plugin which allows you to customize the order
4
+ in which run your tests are run. It provides the marker ``order ``, that has
5
+ attributes that defines when your tests should run in relation to each other.
6
+ These attributes can be absolute (i.e. first, or second-to-last) or relative
7
+ (i.e. run this test before this other test).
7
8
8
9
Relationship with pytest-ordering
9
10
---------------------------------
@@ -46,8 +47,8 @@ The latest master can be installed from the GitHub sources:
46
47
47
48
pip install git+https://github.com/mrbean-bremen/pytest-order
48
49
49
- Quickstart
50
- ----------
50
+ Overview
51
+ --------
51
52
Ordinarily pytest will run tests in the order that they appear in a module.
52
53
For example, for the following tests:
53
54
@@ -100,11 +101,13 @@ With pytest-order, you can change the default ordering as follows:
100
101
101
102
=========================== 2 passed in 0.01 seconds ===========================
102
103
103
- This is a trivial example, but ordering is respected across test files.
104
- There are several possibilities to define the order.
104
+ Usage
105
+ =====
106
+ The above is a trivial example, but ordering is respected across test files.
107
+ There are currently three possibilities to define the order:
105
108
106
- By number
107
- ---------
109
+ Order by number
110
+ ---------------
108
111
As already shown above, the order can be defined using ordinal numbers.
109
112
Negative numbers are also allowed - they are used the same way as indexes
110
113
are used in Python lists, e.g. to count from the end:
@@ -144,13 +147,14 @@ are used in Python lists, e.g. to count from the end:
144
147
145
148
=========================== 4 passed in 0.02 seconds ===========================
146
149
150
+ There is no limit for the numbers that can be used in this way.
147
151
148
- Ordinals
149
- --------
152
+ Order using ordinals
153
+ --------------------
150
154
151
155
You can also use markers such as "first", "second", "last", and
152
156
"second_to_last". These are convenience notations, and have the same effect
153
- as the numbers 1, 2 , -1 and -2 that have been shown above:
157
+ as the numbers 0, 1 , -1 and -2 that have been shown above:
154
158
155
159
.. code :: python
156
160
@@ -187,9 +191,28 @@ as the numbers 1, 2, -1 and -2 that have been shown above:
187
191
188
192
=========================== 4 passed in 0.02 seconds ===========================
189
193
190
- Relative to other tests
191
- -----------------------
192
-
194
+ Convenience names are only defined for the first and the last 8 numbers,
195
+ here is the complete list with the corresponding numbers:
196
+
197
+ - 'first': 0
198
+ - 'second': 1
199
+ - 'third': 2
200
+ - 'fourth': 3
201
+ - 'fifth': 4
202
+ - 'sixth': 5
203
+ - 'seventh': 6
204
+ - 'eighth': 7
205
+ - 'last': -1
206
+ - 'second_to_last': -2
207
+ - 'third_to_last': -3
208
+ - 'fourth_to_last': -4
209
+ - 'fifth_to_last': -5
210
+ - 'sixth_to_last': -6
211
+ - 'seventh_to_last': -7
212
+ - 'eighth_to_last': -8
213
+
214
+ Order relative to other tests
215
+ -----------------------------
193
216
The test order can be defined relative to other tests, which are referenced
194
217
by their name:
195
218
@@ -222,9 +245,12 @@ by their name:
222
245
223
246
=========================== 4 passed in 0.02 seconds ===========================
224
247
248
+ Configuration
249
+ =============
250
+ Currently there is only one option that changes the behavior of the plugin.
251
+
225
252
``--indulgent-ordering `` and overriding ordering
226
253
------------------------------------------------
227
-
228
254
You may sometimes find that you want to suggest an ordering of tests, while
229
255
allowing it to be overridden for good reason. For example, if you run your test
230
256
suite in parallel and have a number of tests which are particularly slow, it
@@ -239,7 +265,6 @@ pytest-order *before* the sort from ``--failed-first``, allowing the failed
239
265
tests to be sorted to the front.
240
266
241
267
242
-
243
268
.. toctree ::
244
269
:maxdepth: 2
245
270
0 commit comments