gotestsum icon indicating copy to clipboard operation
gotestsum copied to clipboard

Feature request: Report subtests results before the top level test ends

Open aslafy-z opened this issue 4 years ago • 1 comments

I'd love to get details of the subtests with the testname reporter before all of them are executed.

Currently, I only get the result when all the subtests are executed.

aslafy-z avatar Dec 02 '21 13:12 aslafy-z

Thank you for the feature request!

I think unfortunately this will be difficult to implement because go test doesn't send the subtest pass/fail events immediately. You can see the implementation for the testname formatter here: https://github.com/gotestyourself/gotestsum/blob/main/testjson/format.go#L44-L87

That function is called for every event received from go test. There's no buffering of events or anything like that. I haven't tested it, but I think that means it is actually go test that is holding the events until the parent test completes.

I think go test would need to send these events earlier for this to work.

I'm curious, are you using t.Parallel with the subtests? I wonder if that changes the behaviour.

dnephin avatar Dec 04 '21 18:12 dnephin

https://go-review.googlesource.com/c/go/+/443596 (which I think will be released in go1.20) mentions that it fixes this problem. So there's a good chance this problem will be fixed in the next Go release.

dnephin avatar Nov 26 '22 19:11 dnephin

go1.20 is out now

From: https://go.dev/doc/go1.20#go-command

The implementation of go test -json has been improved to make it more robust. Programs that run go test -json do not need any updates. Programs that invoke go tool test2json directly should now run the test binary with -v=test2json (for example, go test -v=test2json or ./pkg.test -test.v=test2json) instead of plain -v.

dprotaso avatar Feb 22 '23 21:02 dprotaso

I stumbled upon this github issue and I can confirm that updating to go 1.20 shows the subtest results immediately

somebody-nobody avatar Apr 11 '23 11:04 somebody-nobody

Thank you for confirming! I'm going to close this issue since it appears to be resolved by changes in the go toolchain.

dnephin avatar Apr 11 '23 17:04 dnephin