diff options
| -rw-r--r-- | nova/test.py | 2 | ||||
| -rw-r--r-- | nova/tests/README.rst | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/nova/test.py b/nova/test.py index cc2466ff3..6dad0784a 100644 --- a/nova/test.py +++ b/nova/test.py @@ -173,9 +173,9 @@ class MoxStubout(fixtures.Fixture): # because it screws with our generators self.mox = mox.Mox() self.stubs = stubout.StubOutForTesting() - self.addCleanup(self.mox.UnsetStubs) self.addCleanup(self.stubs.UnsetAll) self.addCleanup(self.stubs.SmartUnsetAll) + self.addCleanup(self.mox.UnsetStubs) self.addCleanup(self.mox.VerifyAll) diff --git a/nova/tests/README.rst b/nova/tests/README.rst index 76b92258a..9dd7e7e8b 100644 --- a/nova/tests/README.rst +++ b/nova/tests/README.rst @@ -76,3 +76,20 @@ Example:: obj = cls() self.assertRaises(test.TestingException, obj.outer_method) + + +Stubbing and Mocking +-------------------- + +Whenever possible, tests SHOULD NOT stub and mock out the same function. + +If it's unavoidable, tests SHOULD define stubs before mocks since the +`TestCase` cleanup routine will un-mock before un-stubbing. Doing otherwise +results in a test that leaks stubbed functions, causing hard-to-debug +interference between tests [1]_. + +If a mock must take place before a stub, any stubs after the mock call MUST be +manually unset using `self.cleanUp` calls within the test. + + +.. [1] https://bugs.launchpad.net/nova/+bug/1180671 |
