3
3
You can adapt this file completely to your liking, but it should at least
4
4
contain the root `toctree` directive.
5
5
6
- pytest-ordering : run your tests in order
7
- =========================================
6
+ pytest-ordering2 : run your tests in order
7
+ ==========================================
8
8
9
- pytest-ordering is a pytest plugin to run your tests in any order that
9
+ pytest-ordering2 is a pytest plugin to run your tests in any order that
10
10
you specify. It provides custom markers _ that say when your tests should
11
11
run in relation to each other. They can be absolute (i.e. first, or
12
12
second-to-last) or relative (i.e. run this test before this other test).
13
13
14
- .. note :: pytest-ordering is currently alpha-quality software. Notably,
15
- some of this documentation may be aspirational in nature. If something
16
- you read here isn't currently implemented, rest assured that I am working
17
- on it (or feel free to ping me: https://github.com/ftobia)
18
-
19
- Supported python and pytest versions
14
+ Supported Python and pytest versions
20
15
------------------------------------
21
16
22
- pytest-ordering supports python 2.7, 3.4, 3.5, 3.6, 3.7 , and pypy, and is
17
+ pytest-ordering2 supports python 2.7, 3.5 - 3.8 , and pypy, and is
23
18
compatible with pytest 3.6.0 or newer.
24
19
25
20
@@ -57,11 +52,11 @@ With pytest-ordering, you can change the default ordering as follows:
57
52
58
53
import pytest
59
54
60
- @pytest.mark.order2
55
+ @pytest.mark.run ( order = 2 )
61
56
def test_foo ():
62
57
assert True
63
58
64
- @pytest.mark.order1
59
+ @pytest.mark..run ( order = 1 )
65
60
def test_bar ():
66
61
assert True
67
62
@@ -79,29 +74,31 @@ With pytest-ordering, you can change the default ordering as follows:
79
74
=========================== 2 passed in 0.01 seconds ===========================
80
75
81
76
This is a trivial example, but ordering is respected across test files.
77
+ There are several possibilities to define the order.
82
78
83
- Other markers
84
- -------------
85
-
86
- You can also use markers such as "first", "second", "last", and "second_to_last":
79
+ By number
80
+ ---------
81
+ As already shown above, the order can be defined using ordinal numbers.
82
+ Negative numbers are also allowed - they are used the same way as indexes
83
+ used in Python lists, e.g. to count from the end:
87
84
88
85
.. code :: python
89
86
90
87
import pytest
91
88
92
- @pytest.mark.second_to_last
89
+ @pytest.mark.run ( order = - 2 )
93
90
def test_three ():
94
91
assert True
95
92
96
- @pytest.mark.last
93
+ @pytest.mark.run ( order = - 1 )
97
94
def test_four ():
98
95
assert True
99
96
100
- @pytest.mark.second
97
+ @pytest.mark.run ( order = 2 )
101
98
def test_two ():
102
99
assert True
103
100
104
- @pytest.mark.first
101
+ @pytest.mark.run ( order = 1 )
105
102
def test_one ():
106
103
assert True
107
104
@@ -120,87 +117,31 @@ You can also use markers such as "first", "second", "last", and "second_to_last"
120
117
121
118
=========================== 4 passed in 0.02 seconds ===========================
122
119
123
- ``--indulgent-ordering `` and overriding ordering
124
- -------------
125
-
126
- You may sometimes find that you want to suggest an ordering of tests, while
127
- allowing it to be overridden for good reson. For example, if you run your test
128
- suite in parallel and have a number of tests which are particularly slow, it
129
- might be desirable to start those tests running first, in order to optimize
130
- your completion time. You can use the pytest-ordering plugin to inform pytest
131
- of this. Now suppose you also want to prioritize tests which failed during the
132
- previous run, by using the ``--failed-first `` option. By default,
133
- pytest-ordering will override the ``--failed-first `` order, but by adding the
134
- ``--indulgent-ordering `` option, you can ask pytest to run the sort from
135
- pytest-ordering *before * the sort from ``--failed-first ``, allowing the failed
136
- tests to be sorted to the front.
137
-
138
-
139
- Aspirational
140
- ============
141
-
142
- This section is for functionality I'd like to implement.
143
- Documentation-driven design :)
144
120
145
121
Ordinals
146
122
--------
147
123
148
- .. code :: python
149
-
150
- import pytest
151
-
152
- @pytest.mark.run (' second-to-last' )
153
- def test_three ():
154
- assert True
155
-
156
- @pytest.mark.run (' last' )
157
- def test_four ():
158
- assert True
159
-
160
- @pytest.mark.run (' second' )
161
- def test_two ():
162
- assert True
163
-
164
- @pytest.mark.run (' first' )
165
- def test_one ():
166
- assert True
167
-
168
- ::
169
-
170
- $ py.test test_foo.py -vv
171
- ============================= test session starts ==============================
172
- platform darwin -- Python 2.7.5 -- py-1.4.20 -- pytest-2.5.2 -- env/bin/python
173
- plugins: ordering
174
- collected 4 items
175
-
176
- test_foo.py:17: test_one PASSED
177
- test_foo.py:12: test_two PASSED
178
- test_foo.py:3: test_three PASSED
179
- test_foo.py:7: test_four PASSED
180
-
181
- =========================== 4 passed in 0.02 seconds ===========================
182
-
183
-
184
- By number
185
- ---------
124
+ You can also use markers such as "first", "second", "last", and
125
+ "second_to_last". These are convenience notations, and have the same effect
126
+ as the numbers 1, 2, -1 and -2 that have been shown above:
186
127
187
128
.. code :: python
188
129
189
130
import pytest
190
131
191
- @pytest.mark.run ( order = - 2 )
132
+ @pytest.mark.second_to_last
192
133
def test_three ():
193
134
assert True
194
135
195
- @pytest.mark.run ( order = - 1 )
136
+ @pytest.mark.last
196
137
def test_four ():
197
138
assert True
198
139
199
- @pytest.mark.run ( order = 2 )
140
+ @pytest.mark.second
200
141
def test_two ():
201
142
assert True
202
143
203
- @pytest.mark.run ( order = 1 )
144
+ @pytest.mark.first
204
145
def test_one ():
205
146
assert True
206
147
@@ -219,10 +160,11 @@ By number
219
160
220
161
=========================== 4 passed in 0.02 seconds ===========================
221
162
222
-
223
163
Relative to other tests
224
164
-----------------------
225
165
166
+ The test order can be defined relative to other tests, which are referenced
167
+ by their name:
226
168
227
169
.. code :: python
228
170
@@ -253,6 +195,22 @@ Relative to other tests
253
195
254
196
=========================== 4 passed in 0.02 seconds ===========================
255
197
198
+ ``--indulgent-ordering `` and overriding ordering
199
+ ------------------------------------------------
200
+
201
+ You may sometimes find that you want to suggest an ordering of tests, while
202
+ allowing it to be overridden for good reason. For example, if you run your test
203
+ suite in parallel and have a number of tests which are particularly slow, it
204
+ might be desirable to start those tests running first, in order to optimize
205
+ your completion time. You can use the pytest-ordering2 plugin to inform pytest
206
+ of this.
207
+ Now suppose you also want to prioritize tests which failed during the
208
+ previous run, by using the ``--failed-first `` option. By default,
209
+ pytest-ordering will override the ``--failed-first `` order, but by adding the
210
+ ``--indulgent-ordering `` option, you can ask pytest to run the sort from
211
+ pytest-ordering2 *before * the sort from ``--failed-first ``, allowing the failed
212
+ tests to be sorted to the front.
213
+
256
214
257
215
258
216
.. toctree ::
0 commit comments