Mock Python's built in print function
I've tried from mock import Mock import __builtin__ __builtin__.print = Mock() But that raises a syntax error. I've also tried patching it like so @patch('__builtin__.print') def test_something_that_performs_lots_of_prints(self, mock_print): # assert stuff Is there any way to do this? print is a keyword in python 2.x, using it as attribute raises a SyntaxError. You can avoid that by using from __future__ import print_function in the beginning of the file. Note: you can't simply use setattr , because the print function you modified doesn't get invoked unless the print statement is disabled.