Skip to content

Commit 7e491bb

Browse files
committed
Merge branch 'ignore-unknown'
2 parents b911c8b + 67fa9ee commit 7e491bb

File tree

4 files changed

+102
-3
lines changed

4 files changed

+102
-3
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
+ Issue #7: Add a configuration switch to implicitly mark all tests.
99

10+
+ Issue #10: Add an option to ignore unknown dependencies.
11+
1012
** Incompatible changes
1113

1214
+ Prepend the class name to the default test name for test class

doc/src/configuration.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,18 @@ Configuration file options can be set in the `ini file`.
2323
decorated. If set to `True`, the outcome of all tests will be
2424
registered. It has the same effect as if all tests are
2525
implicitly decorated with :func:`pytest.mark.dependency`.
26+
27+
Command line options
28+
--------------------
29+
30+
The following command line options are added by pytest.dependency:
31+
32+
`--ignore-unknown-dependency`
33+
By default, a test will be skipped unless all the dependencies
34+
have been run successful. If this option is set, a test will be
35+
skipped if any of the dependencies has been skipped or failed.
36+
E.g. dependencies that have not been run at all will be ignored.
37+
38+
This may be useful if you run only a subset of the testsuite and
39+
some tests in the selected set are marked to depend on other
40+
tests that have not been selected.

pytest_dependency.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77

88
_automark = False
9+
_ignore_unknown = False
910

1011

1112
def _get_bool(value):
@@ -72,8 +73,13 @@ def addResult(self, item, name, rep):
7273

7374
def checkDepend(self, depends, item):
7475
for i in depends:
75-
if not(i in self.results and self.results[i].isSuccess()):
76-
pytest.skip("%s depends on %s" % (item.name, i))
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))
7783

7884

7985
def depends(request, other):
@@ -102,11 +108,15 @@ def pytest_addoption(parser):
102108
parser.addini("automark_dependency",
103109
"Add the dependency marker to all tests automatically",
104110
default=False)
111+
parser.addoption("--ignore-unknown-dependency",
112+
action="store_true", default=False,
113+
help="ignore dependencies whose outcome is not known")
105114

106115

107116
def pytest_configure(config):
108-
global _automark
117+
global _automark, _ignore_unknown
109118
_automark = _get_bool(config.getini("automark_dependency"))
119+
_ignore_unknown = config.getoption("--ignore-unknown-dependency")
110120

111121

112122
@pytest.hookimpl(tryfirst=True, hookwrapper=True)

tests/test_04_ignore_unknown.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""Test the ignore-unknown-dependency command line option.
2+
"""
3+
4+
import pytest
5+
6+
7+
def test_no_ignore(ctestdir):
8+
"""No command line option, e.g. ignore-unknown-dependency is not set.
9+
10+
Explicitly select only a single test that depends on another one.
11+
Since the other test has not been run at all, the selected test
12+
will be skipped.
13+
"""
14+
ctestdir.makepyfile("""
15+
import pytest
16+
17+
@pytest.mark.dependency()
18+
def test_a():
19+
pass
20+
21+
@pytest.mark.dependency()
22+
def test_b():
23+
pass
24+
25+
@pytest.mark.dependency()
26+
def test_c():
27+
pass
28+
29+
@pytest.mark.dependency(depends=["test_c"])
30+
def test_d():
31+
pass
32+
""")
33+
result = ctestdir.runpytest("--verbose", "test_no_ignore.py::test_d")
34+
result.assert_outcomes(passed=0, skipped=1, failed=0)
35+
result.stdout.fnmatch_lines("""
36+
*::test_d SKIPPED
37+
""")
38+
39+
40+
def test_ignore(ctestdir):
41+
"""Set the ignore-unknown-dependency command line option.
42+
43+
Explicitly select only a single test that depends on another one.
44+
The other test has not been run at all, but since unknown
45+
dependencies will be ignored, the selected test will be run
46+
nevertheless.
47+
"""
48+
ctestdir.makepyfile("""
49+
import pytest
50+
51+
@pytest.mark.dependency()
52+
def test_a():
53+
pass
54+
55+
@pytest.mark.dependency()
56+
def test_b():
57+
pass
58+
59+
@pytest.mark.dependency()
60+
def test_c():
61+
pass
62+
63+
@pytest.mark.dependency(depends=["test_c"])
64+
def test_d():
65+
pass
66+
""")
67+
result = ctestdir.runpytest("--verbose", "--ignore-unknown-dependency",
68+
"test_ignore.py::test_d")
69+
result.assert_outcomes(passed=1, skipped=0, failed=0)
70+
result.stdout.fnmatch_lines("""
71+
*::test_d PASSED
72+
""")

0 commit comments

Comments
 (0)