summaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
authorGustavo Niemeyer <gustavo@niemeyer.net>2008-07-01 14:05:27 -0300
committerGustavo Niemeyer <gustavo@niemeyer.net>2008-07-01 14:05:27 -0300
commita2a848a3c15915639e33241a4016846a9e082906 (patch)
treee3e4a242f36a62535fe09f6b323a47295c091683 /test.py
parent87e6cf304120f11ff7f163f1a98291682c34b988 (diff)
downloadmocker-a2a848a3c15915639e33241a4016846a9e082906.tar.gz
Prevent the MockerTestCase base from leaving the mocker in replay mode
while the base class run() method runs, since this might have additional logic which touches mocked content (time.time() was one case). Thanks to Thomas for the initial debugging.
Diffstat (limited to 'test.py')
-rwxr-xr-xtest.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/test.py b/test.py
index 334407f..4f3c39b 100755
--- a/test.py
+++ b/test.py
@@ -941,6 +941,33 @@ class MockerTestCaseTest(TestCase):
if os.path.exists(path):
shutil.rmtree(path)
+ def test_mocker_is_restored_between_method_return_and_cleanup(self):
+ """
+ Certain base classes which MockerTestCase is mixed with may have
+ additional logic after the real test method is run, but before
+ run() returns. We don't want to perform mocking checks on these.
+ """
+ class CustomTestCase(unittest.TestCase):
+ def run(self, result):
+ import time
+ super(CustomTestCase, self).run(result)
+ self.assertTrue(time.time())
+
+ class MyTest(CustomTestCase, MockerTestCase):
+ def test_method(self):
+ import time
+ time_mock = self.mocker.replace(time.time)
+ time_mock()
+ self.mocker.count(0) # Forbit it entirely.
+ self.mocker.replay()
+
+ result = unittest.TestResult()
+ MyTest("test_method").run(result)
+
+ self.assertEquals(result.errors, [])
+ self.assertEquals(result.failures, [])
+
+
class MockerTest(TestCase):