Skip to content

Commit 489d26c

Browse files
committed
Remove registering unneeded marks
- also remove support for orderXX marks - only order mark supported - fix handling of unsupported order attribute - add information about the difference to pytest-ordering
1 parent 9fa6b7b commit 489d26c

File tree

5 files changed

+86
-46
lines changed

5 files changed

+86
-46
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
### Fixes
6+
- fixes the handling of unknown marker attributes (test had been skipped)
7+
58
## [Version 0.7.1](https://pypi.org/project/pytest-order/0.7.1/)
69
Update after renaming the repository and the package.
710

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
pytest-order [![PyPI version](https://badge.fury.io/py/pytest-order.svg)](https://badge.fury.io/py/pytest-order)
2-
================
1+
pytest-order [![PyPI version](https://badge.fury.io/py/pytest-order.svg)](https://badge.fury.io/py/pytest-order) [![Build Status](https://travis-ci.org/mrbean-bremen/pytest-order.svg?branch=master)](https://travis-ci.org/mrbean-bremen/pytest-order) [![Python version](https://img.shields.io/pypi/pyversions/pytest-order.svg)](https://img.shields.io/pypi/pyversions/pytest-order.svg)
2+
============
33
This is a fork of [pytest-ordering](https://github.com/ftobia/pytest-ordering).
44
That project is not maintained anymore, and there are several helpful PRs
55
waiting for merge. Therefore I decided to create this fork that tries to
@@ -9,14 +9,14 @@ organization as outlined in
99
[this issue](https://github.com/ftobia/pytest-ordering/issues/32). When this
1010
happens, this fork will be obsolete.
1111

12-
_Note:_ ``pytest-order`` is not compatible to ``pytest-ordering`` due to the
13-
changed marker name (``order`` instead of ``run``).
12+
_Note:_ ``pytest-order`` is not compatible with ``pytest-ordering`` due to the
13+
changed marker name (``order`` instead of ``run``). Only the ``order``
14+
marker is supported, support for all additional markers has been removed for
15+
consistence (see [this issue](https://github.com/ftobia/pytest-ordering/issues/38)).
1416

1517

1618
pytest-order is a pytest plugin to run your tests in a specific order.
1719

18-
[![Build Status](https://travis-ci.org/mrbean-bremen/pytest-order.svg?branch=master)](https://travis-ci.org/mrbean-bremen/pytest-order)
19-
2020
Have you ever wanted to easily run one of your tests before any others run?
2121
Or run some tests last? Or run this one test before that other test? Or
2222
make sure that this group of tests runs after this other group of tests?
@@ -27,9 +27,10 @@ Install with:
2727

2828
pip install pytest-order
2929

30-
This defines some pytest markers that you can use in your code.
30+
This defines the ``order`` marker that you can use in your code with
31+
different attributes.
3132

32-
For example, this:
33+
For example, this code:
3334

3435
import pytest
3536

@@ -41,11 +42,11 @@ For example, this:
4142
def test_bar():
4243
assert True
4344

44-
Yields this output:
45+
yields the output:
4546

4647
$ py.test test_foo.py -vv
4748
============================= test session starts ==============================
48-
platform darwin -- Python 2.7.5 -- py-1.4.20 -- pytest-2.5.2 -- env/bin/python
49+
platform darwin -- Python 3.7.1, pytest-5.4.3, py-1.8.1, pluggy-0.13.1 -- env/bin/python
4950
plugins: order
5051
collected 2 items
5152

docs/source/index.rst

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,53 @@
11
pytest-order: run your tests in order
2-
==========================================
3-
2+
======================================
43
pytest-order is a pytest plugin to run your tests in any order that
54
you specify. It provides the marker ``order``, that defines when your tests
65
should run in relation to each other. They can be absolute (i.e. first, or
76
second-to-last) or relative (i.e. run this test before this other test).
87

8+
Relationship with pytest-ordering
9+
---------------------------------
10+
``pytest-order`` is a fork of
11+
`pytest-ordering <https://github.com/ftobia/pytest-ordering>`__, which is
12+
not maintained anymore. The idea and most of the code has been created by
13+
Frank Tobia, the author of that plugin.
14+
15+
However, ``pytest-order`` is not compatible with ``pytest-ordering`` due to the
16+
changed marker name (``order`` instead of ``run``) and the removal of all
17+
other special markers for consistence (see
18+
`this issue <https://github.com/ftobia/pytest-ordering/issues/38>`__). This
19+
also avoids clashes between the plugins if they are both installed.
20+
21+
Here are examples for which markers correspond to markers in
22+
``pytest-ordering``:
23+
24+
- ``pytest.mark.order1``, ``pytest.mark.run(order=1)`` => ``pytest.mark.order(1)``
25+
- ``pytest.mark.first`` => ``pytest.mark.order("first")``
26+
27+
928
Supported Python and pytest versions
1029
------------------------------------
11-
1230
pytest-order supports python 2.7, 3.5 - 3.8, and pypy, and is
13-
compatible with pytest 3.6.0 or newer.
31+
compatible with pytest 3.6.0 or newer. Note that support for Python 2 will
32+
be removed in one of the next versions.
1433

34+
Installation
35+
------------
36+
The latest released version can be installed from
37+
`PyPi <https://pypi.python.org/pypi/pytest-order/>`__:
38+
39+
.. code:: bash
40+
41+
pip install pytest-order
42+
43+
The latest master can be installed from the GitHub sources:
44+
45+
.. code:: bash
46+
47+
pip install git+https://github.com/mrbean-bremen/pytest-order
1548
1649
Quickstart
1750
----------
18-
1951
Ordinarily pytest will run tests in the order that they appear in a module.
2052
For example, for the following tests:
2153

@@ -33,7 +65,7 @@ Here is the output:
3365

3466
$ py.test test_foo.py -vv
3567
============================= test session starts ==============================
36-
platform darwin -- Python 2.7.5 -- py-1.4.20 -- pytest-2.5.2 -- env/bin/python
68+
platform darwin -- Python 3.7.1, pytest-5.4.3, py-1.8.1, pluggy-0.13.1 -- env/bin/python
3769
collected 2 items
3870

3971
test_foo.py:2: test_foo PASSED
@@ -59,8 +91,8 @@ With pytest-order, you can change the default ordering as follows:
5991

6092
$ py.test test_foo.py -vv
6193
============================= test session starts ==============================
62-
platform darwin -- Python 2.7.5 -- py-1.4.20 -- pytest-2.5.2 -- env/bin/python
63-
plugins: ordering
94+
platform darwin -- Python 3.7.1, pytest-5.4.3, py-1.8.1, pluggy-0.13.1 -- env/bin/python
95+
plugins: order
6496
collected 2 items
6597

6698
test_foo.py:7: test_bar PASSED
@@ -101,8 +133,8 @@ are used in Python lists, e.g. to count from the end:
101133

102134
$ py.test test_foo.py -vv
103135
============================= test session starts ==============================
104-
platform darwin -- Python 2.7.5 -- py-1.4.20 -- pytest-2.5.2 -- env/bin/python
105-
plugins: ordering
136+
platform darwin -- Python 3.7.1, pytest-5.4.3, py-1.8.1, pluggy-0.13.1 -- env/bin/python
137+
plugins: order
106138
collected 4 items
107139

108140
test_foo.py:17: test_one PASSED
@@ -144,8 +176,8 @@ as the numbers 1, 2, -1 and -2 that have been shown above:
144176

145177
$ py.test test_foo.py -vv
146178
============================= test session starts ==============================
147-
platform darwin -- Python 2.7.5 -- py-1.4.20 -- pytest-2.5.2 -- env/bin/python
148-
plugins: ordering
179+
platform darwin -- Python 3.7.1, pytest-5.4.3, py-1.8.1, pluggy-0.13.1 -- env/bin/python
180+
plugins: order
149181
collected 4 items
150182

151183
test_foo.py:17: test_one PASSED
@@ -180,8 +212,8 @@ by their name:
180212

181213
$ py.test test_foo.py -vv
182214
============================= test session starts ==============================
183-
platform darwin -- Python 2.7.5 -- py-1.4.20 -- pytest-2.5.2 -- env/bin/python
184-
plugins: ordering
215+
platform darwin -- Python 3.7.1, pytest-5.4.3, py-1.8.1, pluggy-0.13.1 -- env/bin/python
216+
plugins: order
185217
collected 3 items
186218

187219
test_foo.py:11: test_first PASSED

pytest_order/__init__.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ def pytest_configure(config):
4343
)
4444
config.addinivalue_line('markers', config_line)
4545

46-
for mark_name in orders_map.keys():
47-
config_line = '{}: run test {}. {}'.format(mark_name,
48-
mark_name.replace('_', ' '),
49-
provided_by_pytest_order)
50-
config.addinivalue_line('markers', config_line)
51-
5246
if config.getoption('indulgent-ordering'):
5347
# We need to dynamically add this `tryfirst` decorator to the plugin:
5448
# only when the CLI option is present should the decorator be added.
@@ -93,13 +87,7 @@ def get_filename(item):
9387

9488

9589
def mark_binning(item, keys, start, end, before, after, unordered):
96-
match_order = re.compile(r"order(\d+)(:?,|$)")
97-
find_order = match_order.search(",".join(keys))
98-
if find_order:
99-
order = int(find_order.group(1))
100-
start.setdefault(order, []).append(item)
101-
return True
102-
elif "order" in keys:
90+
if "order" in keys:
10391
mark = item.get_closest_marker('order')
10492
order = mark.args[0] if mark.args else None
10593
before_mark = mark.kwargs.get('before')
@@ -111,12 +99,12 @@ def mark_binning(item, keys, start, end, before, after, unordered):
11199
order = orders_map[order]
112100
else:
113101
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)
102+
unordered.append(item)
103+
return False
104+
if order < 0:
105+
end.setdefault(order, []).append(item)
106+
else:
107+
start.setdefault(order, []).append(item)
120108
elif before_mark:
121109
if "." not in before_mark:
122110
prefix = get_filename(item)

tests/test_ordering.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,11 @@ def test_quickstart2(item_names_for):
313313
test_content = """
314314
import pytest
315315
316-
@pytest.mark.order2
316+
@pytest.mark.order(2)
317317
def test_foo():
318318
pass
319319
320-
@pytest.mark.order1
320+
@pytest.mark.order(1)
321321
def test_bar():
322322
pass
323323
"""
@@ -422,4 +422,20 @@ def test_markers_registered(capsys):
422422
pytest.main(['--markers'])
423423
out, err = capsys.readouterr()
424424
assert '@pytest.mark.order' in out
425-
assert out.count('Provided by pytest-order') == 17
425+
# only order is supported as marker
426+
assert out.count('Provided by pytest-order.') == 1
427+
428+
429+
def test_unsupported_order(item_names_for):
430+
test_content = """
431+
import pytest
432+
433+
@pytest.mark.order('unknown')
434+
def test_1():
435+
pass
436+
437+
def test_2():
438+
pass
439+
"""
440+
with pytest.warns(UserWarning, match="Unknown order attribute:'unknown'"):
441+
assert item_names_for(test_content) == ['test_1', 'test_2']

0 commit comments

Comments
 (0)