I’ve got a following structure:
|-- dirBar
| |-- __init__.py
| |-- bar.py
|-- foo.py
`-- test.py
bar.py
def returnBar():
return 'Bar'
foo.py
from dirBar.bar import returnBar
def printFoo():
print returnBar()
test.py
from mock import Mock
from foo import printFoo
from dirBar import bar
bar.returnBar = Mock(return_value='Foo')
printFoo()
the result of python test.py is Bar.
How to mock the printBar to make it return Foo so that printFoo will print it?
EDIT: Without modifying any other file that test.py
I’m guessing you are going to mock the function
returnBar, you’d like to usepatchdecorator: