Skip to content

Commit ca6212e

Browse files
committed
Add "all" depend which skips if any previous test did not pass
1 parent 5e97c07 commit ca6212e

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

pytest_dependency.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,19 @@ def addResult(self, item, name, rep):
7272
status.addResult(rep)
7373

7474
def checkDepend(self, depends, item):
75-
for i in depends:
76-
if i in self.results:
77-
if self.results[i].isSuccess():
78-
continue
79-
else:
80-
if _ignore_unknown:
81-
continue
82-
pytest.skip("%s depends on %s" % (item.name, i))
75+
if depends == "all":
76+
for key in self.results:
77+
if not self.results[key].isSuccess():
78+
pytest.skip("%s depends on all previous tests passing (%s failed)" % (item.name, key))
79+
else:
80+
for i in depends:
81+
if i in self.results:
82+
if self.results[i].isSuccess():
83+
continue
84+
else:
85+
if _ignore_unknown:
86+
continue
87+
pytest.skip("%s depends on %s" % (item.name, i))
8388

8489

8590
def depends(request, other):

tests/test_05_alldepend.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Test the "all" dependency.
2+
"""
3+
4+
import pytest
5+
6+
7+
def test_all(ctestdir):
8+
""" Show that depends="all" causes the test to be skipped if a
9+
previous test has failed """
10+
ctestdir.makepyfile("""
11+
import pytest
12+
13+
@pytest.mark.dependency()
14+
def test_a():
15+
pass
16+
17+
@pytest.mark.dependency(depends="all")
18+
def test_b():
19+
pass
20+
21+
@pytest.mark.dependency()
22+
def test_c():
23+
assert False
24+
25+
@pytest.mark.dependency(depends="all")
26+
def test_d():
27+
pass
28+
29+
class TestClass(object):
30+
31+
@pytest.mark.dependency()
32+
def test_a(self):
33+
pass
34+
35+
@pytest.mark.dependency(depends="all")
36+
def test_b(self):
37+
pass
38+
""")
39+
result = ctestdir.runpytest("--verbose", "test_all.py")
40+
result.assert_outcomes(passed=3, skipped=2, failed=1)
41+
result.stdout.fnmatch_lines("""
42+
*::test_b PASSED
43+
*::test_c FAILED
44+
*::test_d SKIPPED
45+
*::TestClass::test_b SKIPPED
46+
""")

0 commit comments

Comments
 (0)