From 79a85be20bb7f891bb698e6dda162beff84793ab Mon Sep 17 00:00:00 2001 From: Gal Oz Date: Sat, 9 Mar 2019 16:19:20 +0200 Subject: [PATCH 01/13] fix parameterization for dependency tests. Original test name is kept and will remain in failed state if failed once --- .idea/encodings.xml | 4 ++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ .idea/pytest-dependency.iml | 12 ++++++++++++ .idea/vcs.xml | 6 ++++++ .idea/workspace.xml | 8 ++++++++ pytest_dependency.py | 32 +++++++++++++++++++++----------- 7 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/pytest-dependency.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a2e120d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ec8fb33 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/pytest-dependency.iml b/.idea/pytest-dependency.iml new file mode 100644 index 0000000..7c9d48f --- /dev/null +++ b/.idea/pytest-dependency.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..1fe07ad --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/pytest_dependency.py b/pytest_dependency.py index 8a7ce52..833b8a1 100644 --- a/pytest_dependency.py +++ b/pytest_dependency.py @@ -46,11 +46,10 @@ def isSuccess(self): 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 +62,23 @@ def __init__(self): self.results = {} def addResult(self, item, name, rep): + original = item.originalname if not name: if item.cls: name = "%s::%s" % (item.cls.__name__, item.name) + original = "%s::%s" % (item.cls.__name__, item.originalname) else: name = item.name - status = self.results.setdefault(name, DependencyItemStatus()) - status.addResult(rep) + names = set([original, name]) + for name in names: + try: + check = self.results[name].isSuccess() + if not check and len(names) == 2: + continue + except KeyError: + pass + status = self.results.setdefault(name, DependencyItemStatus()) + status.addResult(rep) def checkDepend(self, depends, item): for i in depends: @@ -82,7 +91,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 +114,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 +126,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 +135,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") From c07de378b3643bc8fe92e3e05e410e11617c3a56 Mon Sep 17 00:00:00 2001 From: Gal Oz Date: Sat, 9 Mar 2019 16:28:39 +0200 Subject: [PATCH 02/13] removed garbage files --- .idea/workspace.xml | 123 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1fe07ad..f1d6bda 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,8 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - 1552141057243 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 84de06c77142938951e09b82bd957e0c7d924968 Mon Sep 17 00:00:00 2001 From: Gal Oz Date: Sat, 9 Mar 2019 16:35:15 +0200 Subject: [PATCH 05/13] fix typo --- pytest_dependency.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest_dependency.py b/pytest_dependency.py index 833b8a1..57325f0 100644 --- a/pytest_dependency.py +++ b/pytest_dependency.py @@ -91,7 +91,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 From 064d943f7beba5a1afe0ebc7108187217dd4d906 Mon Sep 17 00:00:00 2001 From: Gal Oz Date: Sat, 9 Mar 2019 17:47:41 +0200 Subject: [PATCH 06/13] fixe test and add mechanism against test name being none if no .originalname --- pytest_dependency.py | 27 ++++++++++++++------------- tests/test_03_skipmsgs.py | 4 ++-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/pytest_dependency.py b/pytest_dependency.py index 57325f0..534628b 100644 --- a/pytest_dependency.py +++ b/pytest_dependency.py @@ -62,23 +62,24 @@ def __init__(self): self.results = {} def addResult(self, item, name, rep): - original = item.originalname + if not name: + original = item.originalname if item.originalname is not None else item.name if item.cls: name = "%s::%s" % (item.cls.__name__, item.name) - original = "%s::%s" % (item.cls.__name__, item.originalname) + original = "%s::%s" % (item.cls.__name__, original) else: name = item.name - names = set([original, name]) - for name in names: - try: - check = self.results[name].isSuccess() - if not check and len(names) == 2: - continue - except KeyError: - pass - status = self.results.setdefault(name, DependencyItemStatus()) - status.addResult(rep) + names = set([original, name]) + for name in names: + try: + check = self.results[name].isSuccess() + if not check and len(names) == 2: + continue + except KeyError: + pass + status = self.results.setdefault(name, DependencyItemStatus()) + status.addResult(rep) def checkDepend(self, depends, item): for i in depends: @@ -91,7 +92,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 diff --git a/tests/test_03_skipmsgs.py b/tests/test_03_skipmsgs.py index 6c828ea..95c7082 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 + SKIPPED * test_c depends on test_b + SKIPPED * test_d depends on test_c """) From 5ec159f1a13965aa1c6a133a8e43c756e02be74f Mon Sep 17 00:00:00 2001 From: Gal Oz Date: Sat, 9 Mar 2019 21:36:20 +0200 Subject: [PATCH 07/13] update requirements --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 67c2db4..7c3d791 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -pytest >=3.6.0 +pytest >=4.0.0 From 755abfdd6eea5ba28b19362a63b64b581310cf04 Mon Sep 17 00:00:00 2001 From: Gal Oz Date: Sat, 9 Mar 2019 23:09:24 +0200 Subject: [PATCH 08/13] fix failed original name node will go back to passed --- pytest_dependency.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pytest_dependency.py b/pytest_dependency.py index 534628b..11fefa4 100644 --- a/pytest_dependency.py +++ b/pytest_dependency.py @@ -73,9 +73,9 @@ def addResult(self, item, name, rep): names = set([original, name]) for name in names: try: - check = self.results[name].isSuccess() - if not check and len(names) == 2: - continue + check = not self.results[name].isSuccess() and None not in self.results.values() + if check and len(names) == 2: + return 1 except KeyError: pass status = self.results.setdefault(name, DependencyItemStatus()) From 3a89839f24e08fa925a6a0116827dc353d534e7f Mon Sep 17 00:00:00 2001 From: Gal Oz Date: Sat, 9 Mar 2019 23:30:26 +0200 Subject: [PATCH 09/13] fix original failed\skipped not sticking --- pytest_dependency.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pytest_dependency.py b/pytest_dependency.py index 11fefa4..c73fee2 100644 --- a/pytest_dependency.py +++ b/pytest_dependency.py @@ -70,14 +70,12 @@ def addResult(self, item, name, rep): original = "%s::%s" % (item.cls.__name__, original) else: name = item.name - names = set([original, name]) - for name in names: - try: - check = not self.results[name].isSuccess() and None not in self.results.values() - if check and len(names) == 2: - return 1 - except KeyError: - pass + try: + check = not self.results[original].isSuccess() and None not in self.results.values() + if check and original != name: + return 1 + except KeyError: + pass status = self.results.setdefault(name, DependencyItemStatus()) status.addResult(rep) From f8e1bfd32b6766daad4f26ea865136e9aad5d1bd Mon Sep 17 00:00:00 2001 From: Gal Oz Date: Sat, 9 Mar 2019 23:33:12 +0200 Subject: [PATCH 10/13] conflict resolution --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7c3d791..67c2db4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -pytest >=4.0.0 +pytest >=3.6.0 From 6c2ea1a78c6808ab83065ad9ec476db239e1d856 Mon Sep 17 00:00:00 2001 From: Gal Oz Date: Sat, 9 Mar 2019 23:34:32 +0200 Subject: [PATCH 11/13] conflict resolution --- tests/test_03_skipmsgs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_03_skipmsgs.py b/tests/test_03_skipmsgs.py index 95c7082..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(""" - SKIPPED * test_c depends on test_b - SKIPPED * test_d depends on test_c + SKIP* test_c depends on test_b + SKIP* test_d depends on test_c """) From 2c5d1d85be91398dc150fe705891fb9a87fb1afe Mon Sep 17 00:00:00 2001 From: Gal Oz Date: Sun, 10 Mar 2019 06:58:10 +0200 Subject: [PATCH 12/13] fix ghost original-name test results --- pytest_dependency.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pytest_dependency.py b/pytest_dependency.py index c73fee2..0265c4e 100644 --- a/pytest_dependency.py +++ b/pytest_dependency.py @@ -42,6 +42,9 @@ 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. @@ -62,22 +65,26 @@ 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: - original = item.originalname if item.originalname is not None else item.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) + + if original != (name or item.name): try: - check = not self.results[original].isSuccess() and None not in self.results.values() - if check and original != name: + check = not self.results[original].isSuccess() and self.results[original].isDone() + if check: return 1 except KeyError: pass - status = self.results.setdefault(name, DependencyItemStatus()) - status.addResult(rep) + status = self.results.setdefault(original, DependencyItemStatus()) + status.addResult(rep) def checkDepend(self, depends, item): for i in depends: From ea8aa7d6e3a05c8293e16b858ac4aab60482ef09 Mon Sep 17 00:00:00 2001 From: Gal Oz Date: Sun, 10 Mar 2019 07:15:22 +0200 Subject: [PATCH 13/13] add named dependency as possible parameteried option --- pytest_dependency.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pytest_dependency.py b/pytest_dependency.py index 0265c4e..4e35f69 100644 --- a/pytest_dependency.py +++ b/pytest_dependency.py @@ -73,10 +73,12 @@ def addResult(self, item, name, rep): 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 != (name or item.name): + if original != item.name: try: check = not self.results[original].isSuccess() and self.results[original].isDone() if check: