Fix multi-layers of stdout diverters

It was possible to undo a previous layer of stdout diversion.

Remove the decorator prepare_stdout and use a contextmanager. This
controls exactly what we do and don't divert. Need to port all tests to
this.
Continue updating tests with capture_output context manager