Skip to content

Commit 766f4b5

Browse files
committed
Change "run" marker to "order", remove other markers
- the separate markers ("first", "last" etc) now are option used with the "order" marker (order("first"))
1 parent d2d4eaf commit 766f4b5

File tree

9 files changed

+109
-121
lines changed

9 files changed

+109
-121
lines changed

CHANGELOG.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22

33
## Unreleased
44

5+
### Changes
6+
- changed the used marker from ``run`` to ``order``, removed all additional
7+
markers (see [#38](https://github.com/ftobia/pytest-ordering/issues/38))
8+
59
## [Version 0.7.0](https://pypi.org/project/pytest-ordering2/0.7.0/)
610
Imported version from [pytest-ordering](https://github.com/ftobia/pytest-ordering),
711
including some PRs (manually merged).
812

913
### Added
10-
- Add support for markers like run(before=...), run(after=), run("first") etc.
14+
- added support for markers like run(before=...), run(after=),
15+
run("first") etc.
1116
(imported from [PR #37](https://github.com/ftobia/pytest-ordering/pull/37))
12-
- Add ``--indulgent-ordering`` to request that the sort from
17+
- added ``--indulgent-ordering`` to request that the sort from
1318
pytest-ordering be run before other plugins. This allows the built-in
1419
``--failed-first`` implementation to override the ordering.
1520
(imported from [PR #50](https://github.com/ftobia/pytest-ordering/pull/50))
16-
- Include LICENSE file in distribution
21+
- include LICENSE file in distribution
1722
(imported from [PR #68](https://github.com/ftobia/pytest-ordering/pull/68))
1823

1924
### Infrastructure
20-
- PR #74 (imported)
21-
Add more pytest versions, fix pytest-cov compatibility issue,
25+
- added more pytest versions, fix pytest-cov compatibility issue,
2226
remove Python 3.4, add Python 3.8
2327
(imported from [PR #74](https://github.com/ftobia/pytest-ordering/pull/74))
2428
- moved documentation to [GitHub Pages](https://mrbean-bremen.github.io/pytest-ordering2/)

docs/source/index.rst

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
.. pytest-ordering documentation master file, created by
2-
sphinx-quickstart on Mon Mar 17 18:20:44 2014.
3-
You can adapt this file completely to your liking, but it should at least
4-
contain the root `toctree` directive.
5-
61
pytest-ordering2: run your tests in order
72
==========================================
83

94
pytest-ordering2 is a pytest plugin to run your tests in any order that
10-
you specify. It provides custom markers_ that say when your tests should
11-
run in relation to each other. They can be absolute (i.e. first, or
5+
you specify. It provides the marker ``order``, that defines when your tests
6+
should run in relation to each other. They can be absolute (i.e. first, or
127
second-to-last) or relative (i.e. run this test before this other test).
138

149
Supported Python and pytest versions
@@ -52,11 +47,11 @@ With pytest-ordering, you can change the default ordering as follows:
5247
5348
import pytest
5449
55-
@pytest.mark.run(order=2)
50+
@pytest.mark.order(2)
5651
def test_foo():
5752
assert True
5853
59-
@pytest.mark..run(order=1)
54+
@pytest.mark.order(1)
6055
def test_bar():
6156
assert True
6257
@@ -80,25 +75,25 @@ By number
8075
---------
8176
As already shown above, the order can be defined using ordinal numbers.
8277
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:
78+
are used in Python lists, e.g. to count from the end:
8479

8580
.. code:: python
8681
8782
import pytest
8883
89-
@pytest.mark.run(order=-2)
84+
@pytest.mark.order(-2)
9085
def test_three():
9186
assert True
9287
93-
@pytest.mark.run(order=-1)
88+
@pytest.mark.order(-1)
9489
def test_four():
9590
assert True
9691
97-
@pytest.mark.run(order=2)
92+
@pytest.mark.order(2)
9893
def test_two():
9994
assert True
10095
101-
@pytest.mark.run(order=1)
96+
@pytest.mark.order(1)
10297
def test_one():
10398
assert True
10499
@@ -129,19 +124,19 @@ as the numbers 1, 2, -1 and -2 that have been shown above:
129124
130125
import pytest
131126
132-
@pytest.mark.second_to_last
127+
@pytest.mark.order('second_to_last')
133128
def test_three():
134129
assert True
135130
136-
@pytest.mark.last
131+
@pytest.mark.order('last')
137132
def test_four():
138133
assert True
139134
140-
@pytest.mark.second
135+
@pytest.mark.order('second')
141136
def test_two():
142137
assert True
143138
144-
@pytest.mark.first
139+
@pytest.mark.order('first')
145140
def test_one():
146141
assert True
147142
@@ -170,7 +165,7 @@ by their name:
170165
171166
import pytest
172167
173-
@pytest.mark.run(after='test_second')
168+
@pytest.mark.order(after='test_second')
174169
def test_third():
175170
assert True
176171
@@ -206,7 +201,7 @@ your completion time. You can use the pytest-ordering2 plugin to inform pytest
206201
of this.
207202
Now suppose you also want to prioritize tests which failed during the
208203
previous run, by using the ``--failed-first`` option. By default,
209-
pytest-ordering will override the ``--failed-first`` order, but by adding the
204+
pytest-ordering2 will override the ``--failed-first`` order, but by adding the
210205
``--indulgent-ordering`` option, you can ask pytest to run the sort from
211206
pytest-ordering2 *before* the sort from ``--failed-first``, allowing the failed
212207
tests to be sorted to the front.

example/test_number.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import pytest
22

33

4-
@pytest.mark.run(order=-2)
4+
@pytest.mark.order(-2)
55
def test_three():
66
assert True
77

88

9-
@pytest.mark.run(order=-1)
9+
@pytest.mark.order(-1)
1010
def test_four():
1111
assert True
1212

1313

14-
@pytest.mark.run(order=2)
14+
@pytest.mark.order(2)
1515
def test_two():
1616
assert True
1717

1818

19-
@pytest.mark.run(order=1)
19+
@pytest.mark.order(1)
2020
def test_one():
2121
assert True

example/test_ordinals.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import pytest
22

33

4-
@pytest.mark.run('second_to_last')
4+
@pytest.mark.order('second_to_last')
55
def test_three():
66
assert True
77

88

9-
@pytest.mark.run('last')
9+
@pytest.mark.order('last')
1010
def test_four():
1111
assert True
1212

1313

14-
@pytest.mark.run('second')
14+
@pytest.mark.order('second')
1515
def test_two():
1616
assert True
1717

1818

19-
@pytest.mark.run('first')
19+
@pytest.mark.order('first')
2020
def test_one():
2121
assert True

example/test_other.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import pytest
22

33

4-
@pytest.mark.second_to_last
4+
@pytest.mark.order('second_to_last')
55
def test_three():
66
assert True
77

88

9-
@pytest.mark.last
9+
@pytest.mark.order('last')
1010
def test_four():
1111
assert True
1212

1313

14-
@pytest.mark.second
14+
@pytest.mark.order('second')
1515
def test_two():
1616
assert True
1717

1818

19-
@pytest.mark.first
19+
@pytest.mark.order('first')
2020
def test_one():
2121
assert True

example/test_relative.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33

4-
@pytest.mark.run(after='test_second')
4+
@pytest.mark.order(after='test_second')
55
def test_third():
66
assert True
77

@@ -10,6 +10,6 @@ def test_second():
1010
assert True
1111

1212

13-
@pytest.mark.run(before='test_second')
13+
@pytest.mark.order(before='test_second')
1414
def test_first():
1515
assert True

pytest_ordering2/__init__.py

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import re
44
import sys
5+
from warnings import warn
56

67
import pytest
78

@@ -28,16 +29,16 @@
2829

2930

3031
def pytest_configure(config):
31-
"""Register the "run" marker and configure the plugin depending on the CLI
32-
options"""
32+
"""Register the "order" marker and configure the plugin depending
33+
on the CLI options"""
3334

3435
provided_by_pytest_ordering = (
3536
'Provided by pytest-ordering2. '
3637
'See also: http://pytest-ordering.readthedocs.org/'
3738
)
3839

3940
config_line = (
40-
'run: specify ordering information for when tests should run '
41+
'order: specify ordering information for when tests should run '
4142
'in relation to one another. ' + provided_by_pytest_ordering
4243
)
4344
config.addinivalue_line('markers', config_line)
@@ -70,9 +71,9 @@ def pytest_addoption(parser):
7071
group = parser.getgroup('ordering')
7172
group.addoption('--indulgent-ordering', action='store_true',
7273
dest='indulgent-ordering', help=
73-
'''Request that the sort \
74-
order provided by pytest-ordering be applied before other sorting, \
75-
allowing the other sorting to have priority''')
74+
'Request that the sort order provided by pytest-order '
75+
'be applied before other sorting, allowing the '
76+
'other sorting to have priority')
7677

7778

7879
class OrderingPlugin(object):
@@ -98,17 +99,24 @@ def mark_binning(item, keys, start, end, before, after, unordered):
9899
order = int(find_order.group(1))
99100
start.setdefault(order, []).append(item)
100101
return True
101-
elif "run" in keys:
102-
mark = item.get_closest_marker('run')
103-
order = mark.kwargs.get('order')
102+
elif "order" in keys:
103+
mark = item.get_closest_marker('order')
104+
order = mark.args[0] if mark.args else None
104105
before_mark = mark.kwargs.get('before')
105106
after_mark = mark.kwargs.get('after')
106107
if order is not None:
107-
order = int(order)
108-
if order < 0:
109-
end.setdefault(order, []).append(item)
108+
if isinstance(order, int):
109+
order = int(order)
110+
elif order in orders_map:
111+
order = orders_map[order]
110112
else:
111-
start.setdefault(order, []).append(item)
113+
warn("Unknown order attribute:'{}'".format(order))
114+
order = None
115+
if order is not None:
116+
if order < 0:
117+
end.setdefault(order, []).append(item)
118+
else:
119+
start.setdefault(order, []).append(item)
112120
elif before_mark:
113121
if "." not in before_mark:
114122
prefix = get_filename(item)
@@ -120,24 +128,7 @@ def mark_binning(item, keys, start, end, before, after, unordered):
120128
after_mark = prefix + "." + after_mark
121129

122130
after.setdefault(after_mark, []).append(item)
123-
else:
124-
for ordinal, position in orders_map.items():
125-
if ordinal in mark.args:
126-
if position < 0:
127-
end.setdefault(position, []).append(item)
128-
else:
129-
start.setdefault(position, []).append(item)
130-
break
131131
return True
132-
for mark_name, order in orders_map.items():
133-
mark = item.get_closest_marker(mark_name)
134-
if mark:
135-
order = int(order)
136-
if order < 0:
137-
end.setdefault(order, []).append(item)
138-
else:
139-
start.setdefault(order, []).append(item)
140-
return True
141132
unordered.append(item)
142133
return False
143134

tests/test_indulgent_ordering.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
2-
import re
32

43
import pytest
4+
55
import pytest_ordering2
66

77
pytest_plugins = ["pytester"]
@@ -14,14 +14,14 @@ def test_run_marker_registered(capsys, tmpdir):
1414
"""
1515
import pytest
1616
17-
@pytest.mark.second
17+
@pytest.mark.order('second')
1818
def test_me_second():
1919
assert True
2020
2121
def test_that_fails():
2222
assert False
2323
24-
@pytest.mark.first
24+
@pytest.mark.order('first')
2525
def test_me_first():
2626
assert True
2727
"""

0 commit comments

Comments
 (0)