From 0b532fda76813ae4793669be5c439f8075bfd9ff Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 15 Jul 2019 22:09:01 +0300 Subject: [PATCH] Remove unnecessary checks from SetupState Since 4622c28ffdd10ff3b3e7c9d4c59ab7c0d1284cc3, _finalizers cannot contain Nones or tuples, so these checks are not longer needed. --- src/_pytest/runner.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index edaee9725..8aae163c3 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -278,10 +278,7 @@ class SetupState: self._finalizers = {} def addfinalizer(self, finalizer, colitem): - """ attach a finalizer to the given colitem. - if colitem is None, this will add a finalizer that - is called at the end of teardown_all(). - """ + """ attach a finalizer to the given colitem. """ assert colitem and not isinstance(colitem, tuple) assert callable(finalizer) # assert colitem in self.stack # some unit tests don't setup stack :/ @@ -309,12 +306,9 @@ class SetupState: def _teardown_with_finalization(self, colitem): self._callfinalizers(colitem) - if hasattr(colitem, "teardown"): - colitem.teardown() + colitem.teardown() for colitem in self._finalizers: - assert ( - colitem is None or colitem in self.stack or isinstance(colitem, tuple) - ) + assert colitem in self.stack def teardown_all(self): while self.stack: