Skip to content

Commit 4aeb566

Browse files
committed
Add the scope argument in the reference documentation.
1 parent 5ab6436 commit 4aeb566

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

doc/src/reference.rst

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Reference
22
=========
33

4-
.. py:decorator:: pytest.mark.dependency(name=None, depends=[])
4+
.. py:decorator:: pytest.mark.dependency(name=None, depends=[], scope='module')
55
66
Mark a test to be used as a dependency for other tests or to
77
depend on other tests.
@@ -11,16 +11,23 @@ Reference
1111
for the test may be set in the depends argument.
1212

1313
:param name: the name of the test to be used for referencing by
14-
dependent tests. If not set, it defaults to the node ID
15-
defined by pytest, that is the name of the test function,
16-
extended by the parameters if applicable. The name must be
17-
unique in the scope, which is currently the test module.
14+
dependent tests. If not set, it defaults to the node ID
15+
defined by pytest, that is the name of the test function,
16+
extended by the parameters if applicable. The name must be
17+
unique in the scope, which is currently the test module.
1818
:type name: :class:`str`
1919
:param depends: dependencies, a list of names of tests that this
2020
test depends on. The test will be skipped unless all of the
21-
dependencies have been run successfully. The dependencies
22-
must also have been decorated by the marker.
21+
dependencies have been run successfully. The dependencies
22+
must also have been decorated by the marker. The names of the
23+
dependencies must be adapted to the scope.
2324
:type depends: iterable of :class:`str`
25+
:param scope: the scope to search for the dependencies. Must be
26+
either `session`, `package`, `module`, or `class`.
27+
:type scope: :class:`str`
28+
29+
.. versionchanged:: 0.5.0
30+
the scope parameter has been added.
2431

2532
.. py:module:: pytest_dependency
2633

pytest_dependency.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def checkDepend(self, depends, item):
8787
pytest.skip("%s depends on %s" % (item.name, i))
8888

8989

90-
def depends(request, other):
90+
def depends(request, other, scope="module"):
9191
"""Add dependency on other test.
9292
9393
Call pytest.skip() unless a successful outcome of all of the tests in
@@ -99,10 +99,17 @@ def depends(request, other):
9999
:param request: the value of the `request` pytest fixture related
100100
to the current test.
101101
:param other: dependencies, a list of names of tests that this
102-
test depends on.
102+
test depends on. The names of the dependencies must be
103+
adapted to the scope.
103104
:type other: iterable of :class:`str`
105+
:param scope: the scope to search for the dependencies. Must be
106+
either `session`, `package`, `module`, or `class`.
107+
:type scope: :class:`str`
104108
105109
.. versionadded:: 0.2
110+
111+
.. versionchanged:: 0.5.0
112+
the scope parameter has been added.
106113
"""
107114
item = request.node
108115
manager = DependencyManager.getManager(item)

0 commit comments

Comments
 (0)