diff --git a/pytest_dependency.py b/pytest_dependency.py index 8a7ce52..4e35f69 100644 --- a/pytest_dependency.py +++ b/pytest_dependency.py @@ -42,15 +42,17 @@ def addResult(self, rep): def isSuccess(self): return list(self.results.values()) == ['passed', 'passed', 'passed'] + def isDone(self): + return None not in list(self.results.values()) + class DependencyManager(object): """Dependency manager, stores the results of tests. """ - - ScopeCls = {'module':pytest.Module, 'session':pytest.Session} + ScopeCls = {'module': pytest.Module, 'session': pytest.Session} @classmethod - def getManager(cls, item, scope='module'): + def getManager(cls, item, scope='module'): # change to session?? """Get the DependencyManager object from the node at scope level. Create it, if not yet present. """ @@ -63,13 +65,28 @@ def __init__(self): self.results = {} def addResult(self, item, name, rep): + original = item.originalname if item.originalname is not None else item.name if not name: if item.cls: name = "%s::%s" % (item.cls.__name__, item.name) + original = "%s::%s" % (item.cls.__name__, original) else: name = item.name - status = self.results.setdefault(name, DependencyItemStatus()) - status.addResult(rep) + + status = self.results.setdefault(name, DependencyItemStatus()) + status.addResult(rep) + else: + original = name + + if original != item.name: + try: + check = not self.results[original].isSuccess() and self.results[original].isDone() + if check: + return 1 + except KeyError: + pass + status = self.results.setdefault(original, DependencyItemStatus()) + status.addResult(rep) def checkDepend(self, depends, item): for i in depends: @@ -82,7 +99,7 @@ def checkDepend(self, depends, item): pytest.skip("%s depends on %s" % (item.name, i)) -def depends(request, other): +def depends(request, other,): """Add dependency on other test. Call pytest.skip() unless a successful outcome of all of the tests in @@ -105,11 +122,11 @@ def depends(request, other): def pytest_addoption(parser): - parser.addini("automark_dependency", - "Add the dependency marker to all tests automatically", + parser.addini("automark_dependency", + "Add the dependency marker to all tests automatically", default=False) - parser.addoption("--ignore-unknown-dependency", - action="store_true", default=False, + parser.addoption("--ignore-unknown-dependency", + action="store_true", default=False, help="ignore dependencies whose outcome is not known") @@ -117,7 +134,7 @@ def pytest_configure(config): global _automark, _ignore_unknown _automark = _get_bool(config.getini("automark_dependency")) _ignore_unknown = config.getoption("--ignore-unknown-dependency") - config.addinivalue_line("markers", + config.addinivalue_line("markers", "dependency(name=None, depends=[]): " "mark a test to be used as a dependency for " "other tests or to depend on other tests.") @@ -126,6 +143,7 @@ def pytest_configure(config): @pytest.hookimpl(tryfirst=True, hookwrapper=True) def pytest_runtest_makereport(item, call): """Store the test outcome if this item is marked "dependency". + """ outcome = yield marker = item.get_closest_marker("dependency") diff --git a/tests/test_03_skipmsgs.py b/tests/test_03_skipmsgs.py index 6c828ea..d501285 100644 --- a/tests/test_03_skipmsgs.py +++ b/tests/test_03_skipmsgs.py @@ -36,6 +36,6 @@ def test_d(): *::test_d SKIPPED """) result.stdout.fnmatch_lines_random(""" - SKIP * test_c depends on test_b - SKIP * test_d depends on test_c + SKIP* test_c depends on test_b + SKIP* test_d depends on test_c """)