derwiki-adroll / mock

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

Feature Request: dot-start notation for target in patch() #146

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I want to write:
>>> from os import path
>>> from mock import patch
>>> @patch('.path.isfile')
... def test_something(mock_isfile):
...     pass
... 
>>> test_something()
>>> 

instead of writing:
>>> @patch('__main__.path.isfile')

>>> @patch.object(path, 'isfile')

>>> @patch('os.path.isfile')

Original issue reported on code.google.com by msm...@gmail.com on 27 Mar 2012 at 12:27

GoogleCodeExporter commented 9 years ago
For that to work patch would have to do frame introspection to work out where 
it is being called from, and I really dislike hackery like that. 

Instead you can do:

    @patch('%s.thing' % __name__)

This has the same effect as your proposed feature, without the hackery.

Original comment by fuzzyman on 27 Mar 2012 at 1:08