@@ -2,10 +2,16 @@ Introduction
2
2
============
3
3
``pytest-order `` is a pytest plugin which allows you to customize the order
4
4
in which 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.
5
+ attributes that define when your tests should run in relation to each other.
6
6
These attributes can be absolute (i.e. first, or second-to-last) or relative
7
7
(i.e. run this test before this other test).
8
8
9
+ .. note ::
10
+ It is generally considered bad practice to write tests that depend on each
11
+ other. However, in reality this may still be needed due to performance
12
+ problems or legacy code. Still, before using this plugin, you should check
13
+ if you can refactor your tests to remove the dependencies between tests.
14
+
9
15
Relationship with pytest-ordering
10
16
---------------------------------
11
17
``pytest-order `` is a fork of
@@ -110,11 +116,11 @@ Usage
110
116
=====
111
117
The above is a trivial example, but ordering is respected across test files.
112
118
113
- .. note ::
114
- The scope of the ordering is always global, e.g. tests with lower ordinal
115
- numbers are always executed before tests with higher numbers, regardless of
116
- the module and class they reside in. This may be changed to be
117
- configurable in a later version .
119
+ .. note ::
120
+ The scope of the ordering is global per default , e.g. tests with lower
121
+ ordinal numbers are always executed before tests with higher numbers,
122
+ regardless of the module and class they reside in. This can be changed
123
+ by using the :ref: ` order-scope ` option .
118
124
119
125
There are currently three possibilities to define the order:
120
126
@@ -257,11 +263,19 @@ by their name:
257
263
258
264
=========================== 4 passed in 0.02 seconds ===========================
259
265
266
+ If a test is referenced using the unqualified test name as shown in the
267
+ example, the test is assumed to be in the current module. For tests in other
268
+ modules the qualified test name (e.g. ``my_module.test_something ``) has to
269
+ be used.
270
+
271
+ If an unknown test is referenced, a warning is issued and the test in
272
+ question is ordered behind all other tests.
273
+
260
274
.. note ::
261
- The `pytest-dependency <https://pypi.org/project/pytest-dependency/ >`__
262
- plugin also manages dependencies between tests (skips tests that depend
263
- on skipped or failed tests), but doesn't do any ordering. You can combine
264
- both plugins if you need both options.
275
+ The `pytest-dependency <https://pypi.org/project/pytest-dependency/ >`__
276
+ plugin also manages dependencies between tests (skips tests that depend
277
+ on skipped or failed tests), but doesn't do any ordering. You can combine
278
+ both plugins if you need both options.
265
279
266
280
Configuration
267
281
=============
@@ -286,6 +300,8 @@ pytest-order *before* the sort from ``--failed-first``, allowing the failed
286
300
tests to be sorted to the front (note that in pytest versions from 6.0 on,
287
301
this seems not to be needed anymore, at least in this specific case).
288
302
303
+ .. _order-scope :
304
+
289
305
``--order-scope ``
290
306
-----------------
291
307
By default, tests are ordered per session, e.g. across all modules in the
@@ -317,6 +333,50 @@ together, we have to put each group of dependent tests in one file, and call
317
333
pytest with ``--dist=loadfile `` (this is taken from
318
334
`this issue <https://github.com/ftobia/pytest-ordering/issues/36 >`__).
319
335
336
+ Sparse ordinal behavior
337
+ -----------------------
338
+ Sparse ordering (e.g. missing some ordinals in your markers) behaves the
339
+ same as if the the ordinals are consecutive. For example, these tests:
340
+
341
+ .. code :: python
342
+
343
+ import pytest
344
+
345
+ @pytest.mark.order (4 )
346
+ def test_two ():
347
+ assert True
348
+
349
+ def test_three ():
350
+ assert True
351
+
352
+ @pytest.mark.order (2 )
353
+ def test_two ():
354
+ assert True
355
+
356
+ have the same output as:
357
+
358
+ .. code :: python
359
+
360
+ import pytest
361
+
362
+ @pytest.mark.order (1 )
363
+ def test_two ():
364
+ assert True
365
+
366
+ def test_three ():
367
+ assert True
368
+
369
+ @pytest.mark.order (0 )
370
+ def test_two ():
371
+ assert True
372
+
373
+ namely, the tests are run in the order ``test_one ``, ``test_two ``,
374
+ ``test_three ``, regardless of the gaps between numbers, and the starting
375
+ number being not 0. It would be possible to change the ordering behavior to
376
+ fill the gaps between the numbers with tests without a marker, as long as
377
+ any are available. However, this leads to some not very intuitive behavior,
378
+ so it is currently not implemented. If there will be demand for this kind
379
+ of behavior, it can be added in a later version.
320
380
321
381
.. toctree ::
322
382
:maxdepth: 2
0 commit comments