-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: testing: report failing test after panic #32121
Comments
It doesn't seem like we can recover during panic, but printing more information as the panic passes by seems like something we should investigate. At the least, we should print the name of the (sub)test that panicked, but we should probably also flush the current test output log, which would mean formatting a failure as well. Does anyone want to sketch out details for this? |
I can try prototyping something if we're okay with the idea in principle. |
Change https://golang.org/cl/179599 mentions this issue: |
Turns out we already flush the test output log on panic, but we don't recursively flush it up to the root so subtest output gets lost. https://golang.org/cl/179599 flushes output to the root, and adds an explicit Example output with this change:
|
This looks fantastic. I could have used this over the weekend. |
Let's get this in early in Go 1.14, just because I kind of remember a previous attempt failing badly. |
Two minor design questions from the CL:
e.g., this could instead be: --- FAIL: Test
--- FAIL: Test/1/0
panic: runtime error: integer divide by zero [recovered]
panic: runtime error: integer divide by zero
goroutine 36 [running]:
testing.tRunner.func1(0xc0000c4300)
/Users/dneil/src/go/src/testing/testing.go:882 +0x5ff
panic(0x111bfa0, 0x1230f50)
/Users/dneil/src/go/src/runtime/panic.go:619 +0x1b2
foo.Test.func1(0xc0000c4300)
/Users/dneil/src/testpanic/panic_test.go:11 +0x24
testing.tRunner(0xc0000c4300, 0xc00008e310)
/Users/dneil/src/go/src/testing/testing.go:917 +0xbf
created by testing.(*T).Run
/Users/dneil/src/go/src/testing/testing.go:968 +0x350
FAIL foo 0.077s |
FWIW, some version of #32333 (fatal panic handler) would let us also produce similar improvements in test output when a panic occurs in a goroutine not started by a Test function. |
When a test panics in a table-driven test, it is difficult to tell which case caused the failure. For example:
We know that
testpanic_test.Test
panicked, but we don't know which test case is to blame. You can get a much more useful error by manually recovering the panic and converting it to at.Fatal
:I propose that the testing package do something like that automatically. Perhaps rather than converting the panic to a
t.Fatal
it should print the failing test name and continue panicking; the important point is to provide information about which test case triggered the panic.This doesn't help with panics in goroutines started by a test, of course.
The text was updated successfully, but these errors were encountered: