Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e212370

Browse files
committed
Use correct methods in unittest.mock examples.
1 parent d0dfe9a commit e212370

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

Doc/library/unittest.mock-examples.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ You can stack up multiple patch decorators using this pattern:
372372
... @patch('package.module.ClassName1')
373373
... @patch('package.module.ClassName2')
374374
... def test_something(self, MockClass2, MockClass1):
375-
... self.assertTrue(package.module.ClassName1 is MockClass1)
376-
... self.assertTrue(package.module.ClassName2 is MockClass2)
375+
... self.assertIs(package.module.ClassName1, MockClass1)
376+
... self.assertIs(package.module.ClassName2, MockClass2)
377377
...
378378
>>> MyTest('test_something').test_something()
379379

@@ -595,10 +595,10 @@ with `test`:
595595
... class MyTest(TestCase):
596596
...
597597
... def test_one(self, MockSomeClass):
598-
... self.assertTrue(mymodule.SomeClass is MockSomeClass)
598+
... self.assertIs(mymodule.SomeClass, MockSomeClass)
599599
...
600600
... def test_two(self, MockSomeClass):
601-
... self.assertTrue(mymodule.SomeClass is MockSomeClass)
601+
... self.assertIs(mymodule.SomeClass, MockSomeClass)
602602
...
603603
... def not_a_test(self):
604604
... return 'something'
@@ -617,7 +617,7 @@ These allow you to move the patching into your `setUp` and `tearDown` methods.
617617
... self.mock_foo = self.patcher.start()
618618
...
619619
... def test_foo(self):
620-
... self.assertTrue(mymodule.foo is self.mock_foo)
620+
... self.assertIs(mymodule.foo, self.mock_foo)
621621
...
622622
... def tearDown(self):
623623
... self.patcher.stop()
@@ -636,7 +636,7 @@ exception is raised in the setUp then tearDown is not called.
636636
... self.mock_foo = patcher.start()
637637
...
638638
... def test_foo(self):
639-
... self.assertTrue(mymodule.foo is self.mock_foo)
639+
... self.assertIs(mymodule.foo, self.mock_foo)
640640
...
641641
>>> MyTest('test_foo').run()
642642

0 commit comments

Comments
 (0)