derwiki-adroll / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Feature Request: The temporary keyword argument of the patch decorators #150

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I want to write:

    @patch('Spam.method', temporary=True)
    def _test_spam(self, args, mock_method):
        # action and assertion

    with self.assertRaises(Exception):
        _test_spam()
    _test_spam('ham')
    _test_spam('eggs')

instead of writing:

    @patch('Spam.method')
    def _test_spam(self, args, mock_method):
       try:
            # action and assertion
        finally:
            mock_method.reset_mock()

    with self.assertRaises(Exception):
        _test_spam()
    _test_spam('ham')
    _test_spam('eggs')

Original issue reported on code.google.com by msm...@gmail.com on 1 Apr 2012 at 1:32

GoogleCodeExporter commented 9 years ago
Every time _test_spam is called a new mock will be created by patch, so as far 
as I can see there is no need to call mock_method.reset() at all. 

Can you show me some actual code that highlights the problem?

Original comment by fuzzyman on 1 Apr 2012 at 9:04

GoogleCodeExporter commented 9 years ago
I'm sorry it was my misunderstanding.

Original comment by msm...@gmail.com on 1 Apr 2012 at 11:21

GoogleCodeExporter commented 9 years ago
Ok, no problem.

Original comment by fuzzyman on 1 Apr 2012 at 11:34