Skip to content

Commit fb246e2

Browse files
authored
Merge pull request #11 from asteriogonzalez/master
show the name of the skipped test
2 parents c767eca + 063433b commit fb246e2

File tree

4 files changed

+67
-7
lines changed

4 files changed

+67
-7
lines changed

doc/examples/basic.out

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
$ py.test -rsx basic.py
2+
============================= test session starts ==============================
3+
platform linux -- Python 3.4.6, pytest-2.8.7, py-1.4.30, pluggy-0.3.1
4+
rootdir: /home/user/pytest-dependency-0.2, inifile:
5+
plugins: dependency-0.2
6+
collected 5 items
7+
8+
basic.py x.s.s
9+
=========================== short test summary info ============================
10+
SKIP [1] /usr/lib/python3.4/site-packages/pytest_dependency.py:65: test_e depends on test_c
11+
SKIP [1] /usr/lib/python3.4/site-packages/pytest_dependency.py:65: test_c depends on test_a
12+
XFAIL basic.py::test_a
13+
deliberate fail
14+
15+
================ 2 passed, 2 skipped, 1 xfailed in 0.02 seconds ================

doc/src/usage.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ Consider the following example test module:
1313
All the tests are decorated with :func:`pytest.mark.dependency`. This
1414
will cause the test results to be registered internally and thus other
1515
tests may depend on them. The list of dependencies of a test may be
16-
set in the optional `depends` argument to the marker. The first test
17-
has deliberately been set to fail to illustrate the effect. We will
18-
get the following resuts:
16+
set in the optional `depends` argument to the marker. Running this
17+
test, we will get the following result:
18+
19+
.. literalinclude:: ../examples/basic.out
20+
21+
The first test has deliberately been set to fail to illustrate the
22+
effect. We will get the following resuts:
1923

2024
`test_a`
2125
deliberatly fails.

pytest_dependency.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ def addResult(self, item, marker, rep):
5959
status = self.results.setdefault(name, DependencyItemStatus())
6060
status.addResult(rep)
6161

62-
def checkDepend(self, depends):
62+
def checkDepend(self, depends, item):
6363
for i in depends:
6464
if not(i in self.results and self.results[i].isSuccess()):
65-
pytest.skip("depends on %s" % i)
65+
pytest.skip("%s depends on %s" % (item.name, i))
6666

6767

6868
def depends(request, other):
@@ -84,7 +84,7 @@ def depends(request, other):
8484
"""
8585
item = request.node
8686
manager = DependencyManager.getManager(item)
87-
manager.checkDepend(other)
87+
manager.checkDepend(other, item)
8888

8989

9090
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
@@ -108,4 +108,4 @@ def pytest_runtest_setup(item):
108108
depends = marker.kwargs.get('depends')
109109
if depends:
110110
manager = DependencyManager.getManager(item)
111-
manager.checkDepend(depends)
111+
manager.checkDepend(depends, item)

tests/test_03_skipmsgs.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Verify the messages issued when a dependent test is skipped.
2+
"""
3+
4+
import pytest
5+
6+
7+
def test_simple(ctestdir):
8+
"""One test fails, other dependent tests are skipped.
9+
This also includes indirect dependencies.
10+
"""
11+
ctestdir.makepyfile("""
12+
import pytest
13+
14+
@pytest.mark.dependency()
15+
def test_a():
16+
pass
17+
18+
@pytest.mark.dependency()
19+
def test_b():
20+
assert False
21+
22+
@pytest.mark.dependency(depends=["test_b"])
23+
def test_c():
24+
pass
25+
26+
@pytest.mark.dependency(depends=["test_c"])
27+
def test_d():
28+
pass
29+
""")
30+
result = ctestdir.runpytest("--verbose", "-rs")
31+
result.assert_outcomes(passed=1, skipped=2, failed=1)
32+
result.stdout.fnmatch_lines("""
33+
*::test_a PASSED
34+
*::test_b FAILED
35+
*::test_c SKIPPED
36+
*::test_d SKIPPED
37+
""")
38+
result.stdout.fnmatch_lines_random("""
39+
SKIP * test_c depends on test_b
40+
SKIP * test_d depends on test_c
41+
""")

0 commit comments

Comments
 (0)