Correctly close output buffer in tests.