@@ -122,9 +122,9 @@ The above is a trivial example, but ordering is respected across test files.
122
122
123
123
.. note ::
124
124
The scope of the ordering is global per default, e.g. tests with lower
125
- ordinal numbers are always executed before tests with higher numbers,
126
- regardless of the module and class they reside in. This can be changed
127
- by using the :ref: `order-scope ` option.
125
+ ordinal numbers are always executed before tests with higher numbers in
126
+ the same test session, regardless of the module and class they reside in.
127
+ This can be changed by using the :ref: `order-scope ` option.
128
128
129
129
Ordering is done either absolutely, by using ordinal numbers that define the
130
130
order, or relative to other tests, using the ``before `` and ``after ``
@@ -186,25 +186,26 @@ Order using ordinals
186
186
187
187
Instead of the numbers, you can use ordinal names such as "first", "second",
188
188
"last", and "second_to_last". These are convenience notations, and have the
189
- same effect as the numbers 0, 1, -1 and -2 that have been shown above:
189
+ same effect as the numbers 0, 1, -1 and -2, respectively, that have been shown
190
+ above:
190
191
191
192
.. code :: python
192
193
193
194
import pytest
194
195
195
- @pytest.mark.order (' second_to_last' )
196
+ @pytest.mark.order (" second_to_last" )
196
197
def test_three ():
197
198
assert True
198
199
199
- @pytest.mark.order (' last' )
200
+ @pytest.mark.order (" last" )
200
201
def test_four ():
201
202
assert True
202
203
203
- @pytest.mark.order (' second' )
204
+ @pytest.mark.order (" second" )
204
205
def test_two ():
205
206
assert True
206
207
207
- @pytest.mark.order (' first' )
208
+ @pytest.mark.order (" first" )
208
209
def test_one ():
209
210
assert True
210
211
@@ -226,29 +227,29 @@ same effect as the numbers 0, 1, -1 and -2 that have been shown above:
226
227
Convenience names are only defined for the first and the last 8 numbers.
227
228
Here is the complete list with the corresponding numbers:
228
229
229
- - ' first' : 0
230
- - ' second' : 1
231
- - ' third' : 2
232
- - ' fourth' : 3
233
- - ' fifth' : 4
234
- - ' sixth' : 5
235
- - ' seventh' : 6
236
- - ' eighth' : 7
237
- - ' last' : -1
238
- - ' second_to_last' : -2
239
- - ' third_to_last' : -3
240
- - ' fourth_to_last' : -4
241
- - ' fifth_to_last' : -5
242
- - ' sixth_to_last' : -6
243
- - ' seventh_to_last' : -7
244
- - ' eighth_to_last' : -8
230
+ - " first" : 0
231
+ - " second" : 1
232
+ - " third" : 2
233
+ - " fourth" : 3
234
+ - " fifth" : 4
235
+ - " sixth" : 5
236
+ - " seventh" : 6
237
+ - " eighth" : 7
238
+ - " last" : -1
239
+ - " second_to_last" : -2
240
+ - " third_to_last" : -3
241
+ - " fourth_to_last" : -4
242
+ - " fifth_to_last" : -5
243
+ - " sixth_to_last" : -6
244
+ - " seventh_to_last" : -7
245
+ - " eighth_to_last" : -8
245
246
246
247
Handling of unordered tests
247
248
~~~~~~~~~~~~~~~~~~~~~~~~~~~
248
249
By default, tests with no ``order `` mark are executed after all tests with
249
250
positive ordinal numbers (or the respective names), and before tests with
250
251
negative ordinal numbers. The order of these tests in relationship to each
251
- other is not changed. This behavior may slightly change if the option
252
+ other is not changed. This behavior will slightly change if the option
252
253
:ref: `sparse-ordering ` is used and the ordinals are not contiguous.
253
254
254
255
@@ -262,14 +263,14 @@ by their name:
262
263
263
264
import pytest
264
265
265
- @pytest.mark.order (after = ' test_second' )
266
+ @pytest.mark.order (after = " test_second" )
266
267
def test_third ():
267
268
assert True
268
269
269
270
def test_second ():
270
271
assert True
271
272
272
- @pytest.mark.order (before = ' test_second' )
273
+ @pytest.mark.order (before = " test_second" )
273
274
def test_first ():
274
275
assert True
275
276
@@ -299,7 +300,7 @@ with a ``::`` suffix has to be prepended to the test name:
299
300
import pytest
300
301
301
302
class TestA :
302
- @pytest.mark.order (after = ' TestB::test_c' )
303
+ @pytest.mark.order (after = " TestB::test_c" )
303
304
def test_a ():
304
305
assert True
305
306
@@ -337,11 +338,11 @@ modules, this could be expressed like:
337
338
338
339
import pytest
339
340
340
- @pytest.mark.order (after = ' test_module_a.TestA::test_a' )
341
+ @pytest.mark.order (after = " test_module_a.TestA::test_a" )
341
342
def test_a ():
342
343
assert True
343
344
344
- @pytest.mark.order (before = ' test_module_c.test_submodule.test_2' )
345
+ @pytest.mark.order (before = " test_module_c.test_submodule.test_2" )
345
346
def test_b ():
346
347
assert True
347
348
@@ -358,7 +359,7 @@ ones. This means that relative ordering always takes preference:
358
359
359
360
import pytest
360
361
361
- @pytest.mark.order (index = 0 , after = ' test_second' )
362
+ @pytest.mark.order (index = 0 , after = " test_second" )
362
363
def test_first ():
363
364
assert True
364
365
@@ -587,7 +588,7 @@ dependency, and is ignored if this is the case. Consider the following:
587
588
def test_a ():
588
589
assert True
589
590
590
- @pytest.mark.dependency (depends = [' test_a' ])
591
+ @pytest.mark.dependency (depends = [" test_a" ])
591
592
@pytest.mark.order (" first" )
592
593
def test_b ():
593
594
assert True
@@ -600,7 +601,7 @@ following tests:
600
601
601
602
import pytest
602
603
603
- @pytest.mark.dependency (depends = [' test_b' ])
604
+ @pytest.mark.dependency (depends = [" test_b" ])
604
605
def test_a ():
605
606
assert True
606
607
0 commit comments