diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index edaee9725a3..8aae163c3d0 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -278,10 +278,7 @@ def __init__(self): 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 @@ def _callfinalizers(self, colitem): 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: