File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1
1
History of changes to pytest-dependency
2
2
=======================================
3
3
4
+ * Version 0.2.0 (not yet released)
5
+
6
+ ** New features
7
+
8
+ + Issue #4: Add a depend() function to add a dependency to a test at
9
+ runtime.
10
+
4
11
* Version 0.1.0 (2017-01-29)
5
12
6
13
+ Initial release as an independent Python module.
Original file line number Diff line number Diff line change @@ -62,6 +62,26 @@ def checkDepend(self, depends):
62
62
pytest .skip ("depends on %s" % i )
63
63
64
64
65
+ def depends (request , other ):
66
+ """Add dependency on other test.
67
+
68
+ Call pytest.skip() unless a successful outcome of all of the tests
69
+ in other has been registered previously. This has the same effect
70
+ as the `depends` keyword argument to the `dependency` marker. In
71
+ contrast to the marker, this function may be called at runtime
72
+ during a test.
73
+
74
+ :param request: the value of the `request` pytest fixture related
75
+ to the current test.
76
+ :param other: dependencies, a list of names of tests that this
77
+ test depends on.
78
+ :type other: iterable of :class:`str`
79
+ """
80
+ item = request .node
81
+ manager = DependencyManager .getManager (item )
82
+ manager .checkDepend (other )
83
+
84
+
65
85
@pytest .hookimpl (tryfirst = True , hookwrapper = True )
66
86
def pytest_runtest_makereport (item , call ):
67
87
"""Store the test outcome if this item is marked "dependency".
Original file line number Diff line number Diff line change
1
+ """Using depends() to mark dependencies at runtime.
2
+ """
3
+
4
+ import pytest
5
+
6
+
7
+ def test_skip_depend_runtime (ctestdir ):
8
+ """One test is skipped, other dependent tests are skipped as well.
9
+ This also includes indirect dependencies.
10
+ """
11
+ ctestdir .makepyfile ("""
12
+ import pytest
13
+ from pytest_dependency import depends
14
+
15
+ @pytest.mark.dependency()
16
+ def test_a():
17
+ pass
18
+
19
+ @pytest.mark.dependency()
20
+ def test_b():
21
+ pytest.skip("explicit skip")
22
+
23
+ @pytest.mark.dependency()
24
+ def test_c(request):
25
+ depends(request, ["test_b"])
26
+ pass
27
+
28
+ @pytest.mark.dependency()
29
+ def test_d(request):
30
+ depends(request, ["test_a", "test_c"])
31
+ pass
32
+ """ )
33
+ result = ctestdir .runpytest ("--verbose" )
34
+ result .assert_outcomes (passed = 1 , skipped = 3 , failed = 0 )
35
+ result .stdout .fnmatch_lines ("""
36
+ *::test_a PASSED
37
+ *::test_b SKIPPED
38
+ *::test_c SKIPPED
39
+ *::test_d SKIPPED
40
+ """ )
You can’t perform that action at this time.
0 commit comments