diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 4b1564791..9cadd2f9d 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -305,13 +305,10 @@ class HookRecorder(object): """return a testreport whose dotted import path matches""" values = [] for rep in self.getreports(names=names): - try: - if not when and rep.when != "call" and rep.passed: - # setup/teardown passing reports - let's ignore those - continue - except AttributeError: - pass - if when and getattr(rep, "when", None) != when: + if not when and rep.when != "call" and rep.passed: + # setup/teardown passing reports - let's ignore those + continue + if when and rep.when != when: continue if not inamepart or inamepart in rep.nodeid.split("::"): values.append(rep) @@ -338,7 +335,7 @@ class HookRecorder(object): failed = [] for rep in self.getreports("pytest_collectreport pytest_runtest_logreport"): if rep.passed: - if getattr(rep, "when", None) == "call": + if rep.when == "call": passed.append(rep) elif rep.skipped: skipped.append(rep) diff --git a/src/_pytest/skipping.py b/src/_pytest/skipping.py index 9f7f525ce..49676aa80 100644 --- a/src/_pytest/skipping.py +++ b/src/_pytest/skipping.py @@ -244,8 +244,11 @@ def folded_skips(skipped): # folding reports with global pytestmark variable # this is workaround, because for now we cannot identify the scope of a skip marker # TODO: revisit after marks scope would be fixed - when = getattr(event, "when", None) - if when == "setup" and "skip" in keywords and "pytestmark" not in keywords: + if ( + event.when == "setup" + and "skip" in keywords + and "pytestmark" not in keywords + ): key = (key[0], None, key[2]) d.setdefault(key, []).append(event) values = []