Call again setup_fixture and cleanup_fixture after they fails.
Change-Id: I09ff4ff013866f14bdd4ba194ea8ea7c81d85b6d
This commit is contained in:
parent
a0c598cd3d
commit
3e0d1f6c54
|
@ -308,21 +308,18 @@ class SharedFixture(fixtures.Fixture):
|
|||
|
||||
"""
|
||||
if not self._setup_executed:
|
||||
try:
|
||||
super(SharedFixture, self).setUp()
|
||||
finally:
|
||||
self._cleanup_executed = False
|
||||
self._setup_executed = True
|
||||
super(SharedFixture, self).setUp()
|
||||
self._cleanup_executed = False
|
||||
self._setup_executed = True
|
||||
|
||||
def cleanUp(self, raise_first=True):
|
||||
"""Executes registered cleanups if any"""
|
||||
try:
|
||||
if not self._cleanup_executed:
|
||||
self.addCleanup(self.cleanup_fixture)
|
||||
return super(SharedFixture, self).cleanUp(raise_first=raise_first)
|
||||
finally:
|
||||
self._setup_executed = False
|
||||
self._cleanup_executed = True
|
||||
if not self._cleanup_executed:
|
||||
self.addCleanup(self.cleanup_fixture)
|
||||
result = super(SharedFixture, self).cleanUp(raise_first=raise_first)
|
||||
self._setup_executed = False
|
||||
self._cleanup_executed = True
|
||||
return result
|
||||
|
||||
def _setUp(self):
|
||||
self.setup_fixture()
|
||||
|
|
|
@ -17,6 +17,7 @@ import sys
|
|||
|
||||
import fixtures
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
import tobiko
|
||||
from tobiko.tests import unit
|
||||
|
@ -37,6 +38,15 @@ class MyBaseFixture(tobiko.SharedFixture):
|
|||
specs=tobiko.SharedFixture.cleanup_fixture)
|
||||
|
||||
|
||||
class MySkyppingFixture(tobiko.SharedFixture):
|
||||
|
||||
def setup_fixture(self):
|
||||
tobiko.skip('some-reason')
|
||||
|
||||
def cleanup_fixture(self):
|
||||
tobiko.skip('some-reason')
|
||||
|
||||
|
||||
class MyFixture(MyBaseFixture):
|
||||
pass
|
||||
|
||||
|
@ -263,6 +273,11 @@ class SharedFixtureTest(unit.TobikoUnitTest):
|
|||
fixture.setUp()
|
||||
fixture.setup_fixture.assert_called_once_with()
|
||||
|
||||
def test_setup_when_skipping(self):
|
||||
fixture = MySkyppingFixture()
|
||||
self.assertRaises(testtools.MultipleExceptions, fixture.setUp)
|
||||
self.assertRaises(testtools.MultipleExceptions, fixture.setUp)
|
||||
|
||||
def test_cleanup(self):
|
||||
fixture = MyFixture()
|
||||
fixture.cleanUp()
|
||||
|
@ -271,8 +286,14 @@ class SharedFixtureTest(unit.TobikoUnitTest):
|
|||
def test_cleanup_twice(self):
|
||||
fixture = MyFixture()
|
||||
fixture.cleanUp()
|
||||
fixture.cleanUp()
|
||||
fixture.cleanup_fixture.assert_called_once_with()
|
||||
|
||||
def test_cleanup_when_skipping(self):
|
||||
fixture = MySkyppingFixture()
|
||||
self.assertRaises(tobiko.SkipException, fixture.cleanUp)
|
||||
self.assertRaises(testtools.MultipleExceptions, fixture.cleanUp)
|
||||
|
||||
def test_lifecycle(self):
|
||||
fixture = MyFixture()
|
||||
|
||||
|
|
Loading…
Reference in New Issue