summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSoren Hansen <soren@linux2go.dk>2013-10-16 08:35:03 +0000
committerSoren Hansen <soren@linux2go.dk>2013-10-16 08:35:03 +0000
commit0eadafedac5bb2a9620a9c0c4c30e33cca9beb70 (patch)
treec7283f69975e40ca937a104deff513c67736fd53
parent0ca8ac5948a70c2e1e8ceb4f939f32170b4e366c (diff)
downloadoslotest-0eadafedac5bb2a9620a9c0c4c30e33cca9beb70.tar.gz
Consolidate the use of stubs
We have two separate StubOutForTesting objects when running tests. One that is instantiated directly in the moxstubout fixture and one that mox has for itself. When a method is stubbed, the overridden method is kept in a cache in the StubOutForTesting instance. When calling UnsetAll() on this instance, the order of the cache is reversed and the original methods are put back in place. This means if you have SomeObject with a method called actual_method and you stub that out with stubs.Set(SomeObject, "actual_method", fake_method) you end up with a this tuple in the cache: (SomeObject, "actual_method", SomeObject.actual_method) If you stub it out again stubs.Set(SomeObject, "actual_method", fake_method2) this tuple is appended to the cache: (SomeObject, "actual_method", fake_method) When calling UnsetAll(), the cache is reversed and becomes: [(SomeObject, "actual_method", fake_method), (SomeObject, "actual_method", SomeObject.actual_method)] So first, SomeObject.actual_method (which currently is fake_method2) is set to fake_method, and then set to the original SomeObject.actual_method medthod. If, however, you stub out the same method using both mox and our own StubOutForTesting object, one of the caches will have (SomeObject, "actual_method", SomeObject.actual_method) and the other will have: (SomeObject, "actual_method", fake_method) At this point, restoring everything back to the original state depends on these StubOutForTesting objects getting cleaned up in the correct order. If it's done in the wrong order, SomeObject.actual_method (currently set to fake_method2) will get reset to the original SomeObject.actual_method and subsequently get "reset" to fake_method which makes life miserable for subsequent tests that might rely on the real implementation. This change stops us from having two separate StubOutForTesting objects by simply using mox's all the time. Fixes bug #1239898 Change-Id: I3a768eca3432e6df09c87bd86bffa9763aabfbed
-rw-r--r--openstack/common/fixture/moxstubout.py5
1 files changed, 1 insertions, 4 deletions
diff --git a/openstack/common/fixture/moxstubout.py b/openstack/common/fixture/moxstubout.py
index f277fdd..a0e74fd 100644
--- a/openstack/common/fixture/moxstubout.py
+++ b/openstack/common/fixture/moxstubout.py
@@ -19,7 +19,6 @@
import fixtures
import mox
-import stubout
class MoxStubout(fixtures.Fixture):
@@ -30,8 +29,6 @@ class MoxStubout(fixtures.Fixture):
# emulate some of the mox stuff, we can't use the metaclass
# because it screws with our generators
self.mox = mox.Mox()
- self.stubs = stubout.StubOutForTesting()
+ self.stubs = self.mox.stubs
self.addCleanup(self.mox.UnsetStubs)
- self.addCleanup(self.stubs.UnsetAll)
- self.addCleanup(self.stubs.SmartUnsetAll)
self.addCleanup(self.mox.VerifyAll)