Skip to content

Commit b1bd987

Browse files
committed
Use string lists instead of space separated strings for multiple relational markers
- conforms to pytest-dependency, and is better readable and intuitive - see #24
1 parent 70b3f55 commit b1bd987

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ version 1.0.0, which is planned for the near future.
99
### New features
1010
- added support for more than one relative marker for the same test
1111

12+
### Infrastructure
13+
- added Python 3.10 to CI tests
14+
1215
## [Version 0.10.0](https://pypi.org/project/pytest-order/0.10.0/) (2021-03-18)
1316
Adds support for class-level relative markers and directory level scope.
1417

1518
### New features
1619
- added support for class level relative markers,
1720
see [#7](https://github.com/pytest-dev/pytest-order/issues/7)
18-
- added option `--order-scope-level` which allows to groups tests on the
21+
- added option `--order-scope-level` which allows grouping tests on the
1922
same directory level,
2023
see [#8](https://github.com/pytest-dev/pytest-order/issues/8)
2124

@@ -53,7 +56,8 @@ Patch release to make packaging easier.
5356
### Infrastructure
5457
- use codecov instead of coveralls, that is failing
5558
- added pytest 6.2 to CI tests
56-
- added tests, examples and documentation to source package
59+
- added tests, examples and documentation to source package,
60+
see [#5](https://github.com/pytest-dev/pytest-order/issues/5)
5761

5862
## [Version 0.9.3](https://pypi.org/project/pytest-order/0.9.3/) (2021-01-14)
5963
Bugfix release.

docs/source/index.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ modules, this could be expressed like:
392392
def test_b():
393393
assert True
394394
395-
If an unknown test is referenced, a warning is issued and the test in
396-
question is ordered behind all other tests.
395+
If an unknown test is referenced, a warning is issued and the execution
396+
order of the test in is not changed.
397397

398398
Markers on class level
399399
~~~~~~~~~~~~~~~~~~~~~~
@@ -461,13 +461,13 @@ Several relationships for the same marker
461461
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
462462
If you need to order a certain test relative to more than one other test, you
463463
can add more than one test name to the ``before`` or ``after`` marker
464-
attributes, separated by spaces:
464+
attributes by using a list of test names:
465465

466466
.. code:: python
467467
468468
import pytest
469469
470-
@pytest.mark.order(after="test_second other_module.test_other")
470+
@pytest.mark.order(after=["test_second", "other_module.test_other"])
471471
def test_first():
472472
assert True
473473
@@ -584,9 +584,9 @@ Consider the following directory structure:
584584
test_a.py
585585
test_b.py
586586
feature2
587-
__init__.py
588-
test_a.py
589-
test_b.py
587+
__init__.py
588+
test_a.py
589+
test_b.py
590590

591591
with the test contents:
592592

@@ -677,7 +677,7 @@ the first two directory levels:
677677
order_scope_level/feature2/test_a.py::test_four PASSED
678678

679679
Note that using a level of 0 or 1 would cause the same result as session
680-
scope, and any level greater than 2 would emulate module scope.
680+
scope in this example, and any level greater than 2 would emulate module scope.
681681

682682
``--order-group-scope``
683683
-----------------------

pytest_order/sorter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,18 @@ def is_mark_for_class():
241241

242242
def handle_relative_marks(self, item, mark):
243243
has_relative_marks = False
244-
before_marks = mark.kwargs.get("before", "").split()
244+
before_marks = mark.kwargs.get("before", [])
245+
if before_marks and not isinstance(before_marks, list):
246+
before_marks = [before_marks]
245247
for before_mark in before_marks:
246248
if self.handle_before_or_after_mark(
247249
item, mark, before_mark, is_after=False):
248250
has_relative_marks = True
249251
else:
250252
self.warn_about_unknown_test(before_mark)
251-
after_marks = mark.kwargs.get("after", "").split()
253+
after_marks = mark.kwargs.get("after", [])
254+
if after_marks and not isinstance(after_marks, list):
255+
after_marks = [after_marks]
252256
for after_mark in after_marks:
253257
if self.handle_before_or_after_mark(
254258
item, mark, after_mark, is_after=True):

tests/test_relative_ordering.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def test_multiple_markers_in_same_test(item_names_for):
330330
test_content = """
331331
import pytest
332332
333-
@pytest.mark.order(after="test_3 test_4 test_5")
333+
@pytest.mark.order(after=["test_3", "test_4", "test_5"])
334334
def test_1():
335335
pass
336336
@@ -340,7 +340,7 @@ def test_2():
340340
def test_3():
341341
pass
342342
343-
@pytest.mark.order(before="test_3 test_2")
343+
@pytest.mark.order(before=["test_3", "test_2"])
344344
def test_4():
345345
pass
346346

0 commit comments

Comments
 (0)