mirror of https://github.com/python/cpython
Merge unittest.mock examples fixes.
This commit is contained in:
commit
594f20cd00
|
@ -372,8 +372,8 @@ You can stack up multiple patch decorators using this pattern:
|
||||||
... @patch('package.module.ClassName1')
|
... @patch('package.module.ClassName1')
|
||||||
... @patch('package.module.ClassName2')
|
... @patch('package.module.ClassName2')
|
||||||
... def test_something(self, MockClass2, MockClass1):
|
... def test_something(self, MockClass2, MockClass1):
|
||||||
... self.assertTrue(package.module.ClassName1 is MockClass1)
|
... self.assertIs(package.module.ClassName1, MockClass1)
|
||||||
... self.assertTrue(package.module.ClassName2 is MockClass2)
|
... self.assertIs(package.module.ClassName2, MockClass2)
|
||||||
...
|
...
|
||||||
>>> MyTest('test_something').test_something()
|
>>> MyTest('test_something').test_something()
|
||||||
|
|
||||||
|
@ -595,10 +595,10 @@ with `test`:
|
||||||
... class MyTest(TestCase):
|
... class MyTest(TestCase):
|
||||||
...
|
...
|
||||||
... def test_one(self, MockSomeClass):
|
... def test_one(self, MockSomeClass):
|
||||||
... self.assertTrue(mymodule.SomeClass is MockSomeClass)
|
... self.assertIs(mymodule.SomeClass, MockSomeClass)
|
||||||
...
|
...
|
||||||
... def test_two(self, MockSomeClass):
|
... def test_two(self, MockSomeClass):
|
||||||
... self.assertTrue(mymodule.SomeClass is MockSomeClass)
|
... self.assertIs(mymodule.SomeClass, MockSomeClass)
|
||||||
...
|
...
|
||||||
... def not_a_test(self):
|
... def not_a_test(self):
|
||||||
... return 'something'
|
... return 'something'
|
||||||
|
@ -617,7 +617,7 @@ These allow you to move the patching into your `setUp` and `tearDown` methods.
|
||||||
... self.mock_foo = self.patcher.start()
|
... self.mock_foo = self.patcher.start()
|
||||||
...
|
...
|
||||||
... def test_foo(self):
|
... def test_foo(self):
|
||||||
... self.assertTrue(mymodule.foo is self.mock_foo)
|
... self.assertIs(mymodule.foo, self.mock_foo)
|
||||||
...
|
...
|
||||||
... def tearDown(self):
|
... def tearDown(self):
|
||||||
... self.patcher.stop()
|
... self.patcher.stop()
|
||||||
|
@ -636,7 +636,7 @@ exception is raised in the setUp then tearDown is not called.
|
||||||
... self.mock_foo = patcher.start()
|
... self.mock_foo = patcher.start()
|
||||||
...
|
...
|
||||||
... def test_foo(self):
|
... def test_foo(self):
|
||||||
... self.assertTrue(mymodule.foo is self.mock_foo)
|
... self.assertIs(mymodule.foo, self.mock_foo)
|
||||||
...
|
...
|
||||||
>>> MyTest('test_foo').run()
|
>>> MyTest('test_foo').run()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue