I\'ve tried
from mock import Mock
import __builtin__
__builtin__.print = Mock()
But that raises a syntax error. I\'ve also tried patching
First, the module is called __builtins__
and you don't need to import it.
Now, in Python 2 print
is a keyword so you can't use it as an attribute name directly. You can use setattr
/getattr
to workaround it:
getattr(__builtins__, "print")
Another option is to use from __future__ import print_function
which changes how Python parses the module to Python 3 syntax.