Sorry, there might be strange formatting in my message above. I copied it from comp.lang.python and then pasted it to this list, and forgot to rectify it.<br><br><div class="gmail_quote">On 25 February 2010 17:06, Максим Lacrima <span dir="ltr"><<a href="mailto:lacrima.maxim@gmail.com">lacrima.maxim@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><font face="Courier, Monospaced">Hello! <br> </font><p><font face="Courier, Monospaced">I use mock library <a rel="nofollow" href="http://www.google.com/url?sa=D&q=http://www.voidspace.org.uk/python/mock/&usg=AFQjCNESuRzqmFZL9VJ0F-gIZbCJA8bZGw" target="_blank">http://www.voidspace.org.uk/python/mock/</a>. There is <br>
no user group for the library, so I post in comp.lang.python and hope <br> that people who use it will help me. <br> </font></p><p><font face="Courier, Monospaced">The library allows to patch objects, using patch decorator. Patching <br>
is done only within the scope of the function. So if I have a lot of <br> tests that need specific object to be patched I have to specify the <br> same decorator for each test method: <br> </font></p><p><font face="Courier, Monospaced">class TestSomething(unittest.TestCase): <br>
</font></p><p><font face="Courier, Monospaced"> @patch('module.Class', spec = True) <br> def test_method1(self, MockClass): <br> Class() <br> self.assertTrue(MockClass.called) <br>
</font></p><p><font face="Courier, Monospaced"> @patch('module.Class', spec = True) <br> def test_method2(self, MockClass): <br> Class() <br> MockClass.assert_called_with('foo') <br>
</font></p><p><font face="Courier, Monospaced"> @patch('module.Class', spec = True) <br> def test_method3(self, MockClass): <br> foo = Class() <br> self.assertRaises(AttributeError, foo.some_method) <br>
</font></p><p><font face="Courier, Monospaced"> # and more ... <br> </font></p><p><font face="Courier, Monospaced">So for every test method I always do the same patching! How can I <br>
avoid this? <br> </font></p><p><font face="Courier, Monospaced">Thanks in advance. <br> Sorry if my English isn't proper enough. <br> </font></p><font face="Courier, Monospaced">With regards, <br>
Maxim. </font>
</blockquote></div><br>