From 960ebae943927805091153bfe17677c5f3734198 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 1 Jan 2021 14:13:39 +0200 Subject: runner: enable a commented assertion in SetupState.addfinalizer The assertion ensures that when `addfinalizer(finalizer, node)` is called, the node is in the stack. This then would ensure that the finalization is actually properly executed properly during the node's teardown. Anything else indicates something is wrong. Previous commits fixed all of the tests which previously failed this, so can be reenabeld now. --- src/_pytest/runner.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index 3aa0a6c4b..9759441bd 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -434,8 +434,8 @@ class SetupState: """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 :/ - self._finalizers.setdefault(colitem, []).append(finalizer) + assert colitem in self.stack, (colitem, self.stack) + self._finalizers[colitem].append(finalizer) def teardown_exact(self, nextitem: Optional[Item]) -> None: needed_collectors = nextitem and nextitem.listchain() or [] -- cgit v1.2.3