From 59369651dbe6a3bac420e16dcded9ad095b1680b Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 12 Nov 2019 14:03:40 -0300 Subject: [PATCH] Bring back explicit tear down Otherwise 'normal' failures won't call teardown explicitly --- src/_pytest/unittest.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/_pytest/unittest.py b/src/_pytest/unittest.py index de6be7dc5..71ff580a6 100644 --- a/src/_pytest/unittest.py +++ b/src/_pytest/unittest.py @@ -110,12 +110,15 @@ class TestCaseFunction(Function): _testcase = None def setup(self): + self._needs_explicit_tearDown = False self._testcase = self.parent.obj(self.name) self._obj = getattr(self._testcase, self.name) if hasattr(self, "_request"): self._request._fillfixtures() def teardown(self): + if self._needs_explicit_tearDown: + self._testcase.tearDown() self._testcase = None self._obj = None @@ -217,6 +220,7 @@ class TestCaseFunction(Function): expecting_failure = self._expecting_failure(testMethod) if expecting_failure: raise + self._needs_explicit_tearDown = True raise _GetOutOf_testPartExecutor(exc) setattr(self._testcase, self._testcase._testMethodName, wrapped_testMethod)