Skip to content

Commit 7523584

Browse files
committed
Add an option to automatically mark all tests.
1 parent cc4252f commit 7523584

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

pytest_dependency.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55

66
import pytest
77

8+
_automark = False
9+
10+
11+
def _get_bool(value):
12+
"""Evaluate string representation of a boolean value.
13+
"""
14+
if value:
15+
if value.lower() in ["0", "no", "n", "false", "f", "off"]:
16+
return False
17+
elif value.lower() in ["1", "yes", "y", "true", "t", "on"]:
18+
return True
19+
else:
20+
raise ValueError("Invalid truth value '%s'" % value)
21+
else:
22+
return False
23+
824

925
class DependencyItemStatus(object):
1026
"""Status of a test item in a dependency manager.
@@ -45,8 +61,7 @@ def getManager(cls, item, scope='module'):
4561
def __init__(self):
4662
self.results = {}
4763

48-
def addResult(self, item, marker, rep):
49-
name = marker.kwargs.get('name')
64+
def addResult(self, item, name, rep):
5065
if not name:
5166
if item.cls:
5267
name = "%s::%s" % (item.cls.__name__, item.name)
@@ -83,16 +98,28 @@ def depends(request, other):
8398
manager.checkDepend(other, item)
8499

85100

101+
def pytest_addoption(parser):
102+
parser.addini("automark_dependency",
103+
"Add the dependency marker to all tests automatically",
104+
default=False)
105+
106+
107+
def pytest_configure(config):
108+
global _automark
109+
_automark = _get_bool(config.getini("automark_dependency"))
110+
111+
86112
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
87113
def pytest_runtest_makereport(item, call):
88114
"""Store the test outcome if this item is marked "dependency".
89115
"""
90116
outcome = yield
91117
marker = item.get_marker("dependency")
92-
if marker is not None:
118+
if marker is not None or _automark:
93119
rep = outcome.get_result()
120+
name = marker.kwargs.get('name') if marker is not None else None
94121
manager = DependencyManager.getManager(item)
95-
manager.addResult(item, marker, rep)
122+
manager.addResult(item, name, rep)
96123

97124

98125
def pytest_runtest_setup(item):

0 commit comments

Comments
 (0)