Python3
import sys, io
stdout = sys.stdout
sys.stdout = io.StringIO()
# call module that calls print()
import module1
module1.test() #另一个模块
# get output and restore sys.stdout
output = sys.stdout.getvalue()
sys.stdout = stdout
print(output)