-
Notifications
You must be signed in to change notification settings - Fork 18k
testing: t.FailNow() in a deferred function masks test panic #29207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Probably |
CC @mpvl @josharian |
I don't see how What does this come up, though? Why defer a call to |
Hmm, good point. Unfortunately, it appears that |
Test helpers that are deferred. E.g. to cleanup temp files. |
I could change calls to |
@seankhliao: is the I'm wondering whether the |
|
When a test panics, any deferred functions will still process allowing the test to properly clean up. If a deferred function executes
t.FailNow()
the test output will not include any information on the panic or the panic's goroutine trace.An example is shown here: https://play.golang.org/p/gWPDVluKaST
Despite that test clearly panicking with a
t.FailNow()
in the deferred function the test output only shows:The desired behavior would be along the lines of this example: https://play.golang.org/p/qrLtmYnkqAh. (Where the deferred function calls
runtime.Goexit()
instead) This produces the following output:I believe this is the result of this line:
go/src/testing/testing.go
Line 813 in bbae8d5
!t.finished
will return false becauset.Now()
marks the test finished and err will be nil because theruntime.Goexit()
int.FatalNow()
is what is being recovered (not the original panic).This prevents the expected panic on this line:
go/src/testing/testing.go
Line 827 in bbae8d5
The text was updated successfully, but these errors were encountered: