mocking - Mock an object in a method that is not a parameter in python -


(i'm python newbie)

i looking at: mocking out objects , methods

and wondering if can replace object in python method not passed parameter, lets method this:

def mypymethod(param1)   myresult = os.path.something   return myresult 

and wish test mypymethod wish os.path @ case return "yourmockresult" when call test method

anyway can this? thanks!!

you should use michael foord's mock module same.

from documentation:

>>> mock import mock >>> real = productionclass() >>> real.method = mock(return_value=3) >>> real.method(3, 4, 5, key='value') 3 >>> real.method.assert_called_with(3, 4, 5, key='value') 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -