You might want to see what I am doing here as an example of how to capture output: https://github.com/scopatz/xdress/blob/tests/tests/tools.py#L36