缓冲测试输出

When testing multiple packages go test buffers the output unless there is a failure, however when benchmarking it defaults to streaming output.

From the 1.3 source :

    // stream test output (no buffering) when no package has
    // been given on the command line (implicit current directory)
    // or when benchmarking.
    // Also stream if we're showing output anyway with a
    // single package under test.  In that case, streaming the
    // output produces the same result as not streaming,
    // just more immediately.
    testStreamOutput = len(pkgArgs) == 0 || testBench ||
            (len(pkgs) <= 1 && testShowPass)

I don't really get this behavior being forced on the user, as I don't see much use in getting the standard ouput during benchmarking.

Here is an example of my test command, which compiles a coverage profile and performs benchmarking for a single package :

go test -bench=. -benchmem -covermode=count -coverprofile=main.coverprofile PACKAGE

Am I missing something? How can I override this behavior and buffer the output even when benchmarking?

If you are writing output during a benchmark it will have an effect on the benchmark results. Therefore it should be included in the benchmark and it should not be deferred or suppressed. If you don't want to see the effects of writing output, change your benchmark.