You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been writing myself some test helpers to set up/tear down some expensive database state and noticed when my tests panicked the tear down wouldn't get run. Eventually, I realized that subtests won't run any defered funcs that were set up before the subtest.
I'd expect this example to run both defered funcs, but when running it, this is the output I see.
$ go test -v .
=== RUN TestRunPanic
=== RUN TestRunPanic/subtest
inner deferred
panic: boom [recovered]
panic: boom
This was pretty surprising to me! After looking through the source of t.Run it makes sense, given that the test/panic is being run in a separate goroutine, but the docs for sub-tests and sub-benchmarks don't seem to mention that.
What version of Go are you using (go version)?
go version go1.8.1 darwin/amd64
What operating system and processor architecture are you using (go env)?
The text was updated successfully, but these errors were encountered:
ianlancetaylor
changed the title
panic in a subtest doesn't execute any deferred funcs outside of the subtest
testing: panic in a subtest doesn't execute any deferred funcs outside of the subtest
May 17, 2017
Top-level tests are subtests from a hidden main tests and just work exactly the same. But this is not clear from the context. Sent out a CL to clarify.
What did you do?
I've been writing myself some test helpers to set up/tear down some expensive database state and noticed when my tests panicked the tear down wouldn't get run. Eventually, I realized that subtests won't run any
defer
ed funcs that were set up before the subtest.I'd expect this example to run both
defer
ed funcs, but when running it, this is the output I see.This was pretty surprising to me! After looking through the source of
t.Run
it makes sense, given that the test/panic is being run in a separate goroutine, but the docs for sub-tests and sub-benchmarks don't seem to mention that.What version of Go are you using (
go version
)?go version go1.8.1 darwin/amd64
What operating system and processor architecture are you using (
go env
)?GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
The text was updated successfully, but these errors were encountered: