Skip to content

Commit 5adffde

Browse files
committed
Add a documentation section on logical combinations of dependencies
1 parent 77b9c1e commit 5adffde

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

doc/examples/or_dependency.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@
22
from pytest_dependency import depends
33

44
def depends_or(request, other, scope='module'):
5-
"""Add dependency on any of the other tests.
6-
7-
Call pytest.skip() unless a successful outcome of any of the tests
8-
in `other` has been registered previously. This helper is similar
9-
to `pytest_dependency.depends()`. It takes the same arguments.
10-
But while `pytest_dependency.depends()` combines the tests in
11-
`other` in an and-like manner, it skips the current test unless
12-
all other tests did succeed, this function combines them in an
13-
or-like manner, it runs the current test if at least one of the
14-
other tests did succeed.
15-
"""
165
item = request.node
176
for o in other:
187
try:

doc/src/advanced.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,31 @@ It requires the parameter values to be scalars that can easily be
8080
converted to strings. And it will fail if the same list of parameters
8181
is passed to the same test more then once, because then, pytest will
8282
add an index to the name to disambiguate the parameter values.
83+
84+
Logical combinations of dependencies
85+
------------------------------------
86+
87+
The dependencies passed as in the `depends` argument to the
88+
:func:`pytest.mark.dependency` marker are combined in an and-like
89+
manner: the current test is skipped unless *all* dependencies did
90+
succeed. Sometimes one may want to combine the dependencies in a
91+
different way. This is not supported by pytest-dependency out of the
92+
box, but it is not difficult to implement. Consider the following
93+
example:
94+
95+
.. literalinclude:: ../examples/or_dependency.py
96+
97+
The helper function `depends_or()` is similar to
98+
:func:`pytest_dependency.depends`, it takes the same arguments. The
99+
only difference is that it combines the dependencies passed in the
100+
`other` argument in an or-like manner: the current test will be run if
101+
*at least one* of the other tests did succeed.
102+
103+
The tests `test_c`, `test_d`, `test_e`, and `test_f` in this example
104+
all depend on two other tests. Only `test_c` will be skipped, because
105+
all tests in its dependency list fail. The other ones are run,
106+
because they have at least one succeeding test in their dependency
107+
list.
108+
109+
Other logical combinations of dependencies are conceivable and may be
110+
implemented in a similar way, according to the use case at hand.

0 commit comments

Comments
 (0)