'Test with replaced stdout.'

def test_stdout_replaced(self, capsys):

    data = io.StringIO()
    new_stdout = io.StringIO()
    with utils.fake_io(data.write):
        sys.stdout.write('hello\n')
        sys.stderr.write('world\n')
        sys.stdout = new_stdout
    (out, err) = capsys.readouterr()
    assert (not out)
    assert (not err)
    assert (data.getvalue() == 'hello\nworld\n')
    sys.stdout.write('still    new\n')
    sys.stderr.write('normal\n')
    (out, err) = capsys.readouterr()
    assert (not out)
    assert (err == 'normal\n')
    assert (new_stdout.getvalue() == 'still    new\n')
