import os import sys def no_stdout(func): def wrapper(*args, **kwargs): old_stdout = sys.stdout sys.stdout = open(os.devnull, "w") ret = func(*args, **kwargs) sys.stdout = old_stdout return ret return wrapper