summaryrefslogtreecommitdiff
path: root/oslotest
diff options
context:
space:
mode:
authorJulien Danjou <julien@danjou.info>2015-03-12 14:31:54 +0100
committerJulien Danjou <julien@danjou.info>2015-03-12 14:31:54 +0100
commitfd60b9c02537e8c3e630fcdc8813fd26d1ab6e27 (patch)
tree41a5f21522c9f555ec85330a2dfb80ffe3fdaa74 /oslotest
parent5020f1a8315d76bc2c884adf9c5faf9744462105 (diff)
downloadoslotest-fd60b9c02537e8c3e630fcdc8813fd26d1ab6e27.tar.gz
mockpatch: fix a potential race condition
If start() fails at some point, we may have a partial mock applied, and no cleanup function. So let's start by adding the cleanup function before starting anything. Change-Id: Ic41d65b2da826f982ff020ebd269b7f749dc63a4
Diffstat (limited to 'oslotest')
-rw-r--r--oslotest/mockpatch.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/oslotest/mockpatch.py b/oslotest/mockpatch.py
index 2144ea2..7fbf0a6 100644
--- a/oslotest/mockpatch.py
+++ b/oslotest/mockpatch.py
@@ -31,8 +31,8 @@ class PatchObject(fixtures.Fixture):
def setUp(self):
super(PatchObject, self).setUp()
_p = mock.patch.object(self.obj, self.attr, self.new, **self.kwargs)
- self.mock = _p.start()
self.addCleanup(_p.stop)
+ self.mock = _p.start()
class Patch(fixtures.Fixture):
@@ -46,8 +46,8 @@ class Patch(fixtures.Fixture):
def setUp(self):
super(Patch, self).setUp()
_p = mock.patch(self.obj, self.new, **self.kwargs)
- self.mock = _p.start()
self.addCleanup(_p.stop)
+ self.mock = _p.start()
class Multiple(fixtures.Fixture):
@@ -76,5 +76,5 @@ class Multiple(fixtures.Fixture):
def setUp(self):
super(Multiple, self).setUp()
_p = mock.patch.multiple(self.obj, **self.kwargs)
- self.mock = _p.start()
self.addCleanup(_p.stop)
+ self.mock = _p.start()