Skip to content

Commit 2d84ce8

Browse files
committed
Add support for order group scope for relative markers
- do not re-order tests with unresolved markers - support before/after marker attributes, not yet dependency markers
1 parent 0cf2cd2 commit 2d84ce8

File tree

7 files changed

+442
-105
lines changed

7 files changed

+442
-105
lines changed

CHANGELOG.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
## Unreleased
44

5-
### Added
5+
### Changes
6+
- tests with unresolved relative markers are now handled like tests
7+
without order markers instead of being enqueued after all other tests
8+
9+
### New features
610
- added `group-order-scope` option to allow hierarchical ordering on module
711
and class scope.
812
See [#6](https://github.com/mrbean-bremen/pytest-order/issues/6)
13+
914

1015
## [Version 0.9.4](https://pypi.org/project/pytest-order/0.9.4/) (2021-01-27)
1116
Patch release to make packaging easier.
@@ -49,7 +54,7 @@ demand-driven.
4954
### Changes
5055
- removed support for pytest 3.6 (it still may work, just isn't tested anymore)
5156

52-
### Added
57+
### New features
5358
- added configuration option for sparse sorting, e.g. the possibility to
5459
fill gaps between ordinals with unordered tests (see also
5560
[this issue](https://github.com/ftobia/pytest-ordering/issues/14) in
@@ -60,7 +65,7 @@ demand-driven.
6065
defined by the `pytest-dependency` plugin
6166
- added ``index`` keyword for ordering as alternative to raw number
6267

63-
### Fixed
68+
### Fixes
6469
- correctly handle combined index and dependency attributes
6570

6671
### Infrastructure
@@ -69,7 +74,7 @@ demand-driven.
6974

7075
## [Version 0.8.1](https://pypi.org/project/pytest-order/0.8.1/) (2020-11-02)
7176

72-
### Added
77+
### New features
7378
- added configuration option for sorting scope,
7479
see [#2](https://github.com/mrbean-bremen/pytest-order/issues/2)
7580

@@ -104,7 +109,7 @@ including some PRs (manually merged).
104109
Note: this version has been removed from PyPi to avoid confusion with the
105110
changed name in the next release.
106111

107-
### Added
112+
### New features
108113
- added support for markers like run(before=...), run(after=),
109114
run("first") etc.
110115
(imported from [PR #37](https://github.com/ftobia/pytest-ordering/pull/37))

docs/source/index.rst

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,6 @@ separate test functions, these test functions are handled separately from the
419419
test classes. If a module has no test classes, the effect is the same as
420420
if using ``--order-scope=module``.
421421

422-
.. note::
423-
This option only affects ordinal ordering. Ordering relative to other tests
424-
is always global, as the related tests are referenced by name.
425-
426422
For example consider two test modules:
427423

428424
**tests/test_module1.py**:
@@ -568,17 +564,74 @@ only if the scope is less than the order scope, e.g. there are three
568564
possibilities:
569565

570566
- order scope "session", order group scope "module" - this is shown in the
571-
example above: first tests in eac module are ordered, afterwards the modules
567+
example above: first tests in each module are ordered, afterwards the modules
572568
- order scope "module", order group scope "class" - first orders tests inside
573569
each class, then the classes inside each module
574570
- order scope "session", order group scope "class" - first orders tests inside
575571
each class, then the classes inside each module, and finally the modules
576572
relatively to each other
577573

574+
This option will also work with relative markers.
575+
576+
Here is a similar example using relative markers:
577+
578+
**tests/test_module1.py**:
579+
580+
.. code::
581+
582+
import pytest
583+
584+
@pytest.mark.order(after="test_module2.test1")
585+
def test1():
586+
pass
587+
588+
def test2():
589+
pass
590+
591+
**tests/test_module2.py**:
592+
593+
.. code::
594+
595+
import pytest
596+
597+
def test1():
598+
pass
599+
600+
@pytest.mark.order(before="test1")
601+
def test2():
602+
pass
603+
604+
Here is what you get using different scopes:
605+
606+
::
607+
608+
$ pytest tests -vv
609+
============================= test session starts ==============================
610+
...
611+
612+
tests/test_module1.py:5: test2 PASSED
613+
tests/test_module2.py:9: test1 PASSED
614+
tests/test_module2.py:5: test2 PASSED
615+
tests/test_module1.py:9: test1 PASSED
616+
617+
::
618+
619+
$ pytest tests -vv --order-group-scope=module
620+
============================= test session starts ==============================
621+
...
622+
623+
tests/test_module2.py:9: test1 PASSED
624+
tests/test_module2.py:5: test2 PASSED
625+
tests/test_module1.py:9: test1 PASSED
626+
tests/test_module1.py:5: test2 PASSED
627+
628+
You can see that in the second run the second test module is run before the
629+
first because of the dependency, but the tests inside each module remain in
630+
the same order as before. Note that using module scope as in the example
631+
above doesn't make sense here due to the dependencies between modules.
632+
578633
.. note::
579-
This option currently does not work with relative markers - respective
580-
support may be added later. It will also not work together with the sparse
581-
ordering option.
634+
This option will not work together well with the sparse ordering option.
582635

583636
``--indulgent-ordering``
584637
------------------------

0 commit comments

Comments
 (0)