I\'ve tried
from mock import Mock
import __builtin__
__builtin__.print = Mock()
But that raises a syntax error. I\'ve also tried patching
My version.
In the tested program(ex: pp.py
):
from __future__ import print_function
def my_func():
print('hello')
In the test program:
def test_print(self):
from pp import my_func
from mock import call
with mock.patch('__builtin__.print') as mock_print:
my_func()
mock_print.assert_has_calls(
[
call('hello')
]
)