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
{{ message }}
Repository navigation
testing: invalid testing.go:1343: test executed panic(nil) or runtime.Goexit: subtest may have called FailNow on a parent test error #58129
=== RUN TestRunFatal
=== RUN TestRunFatal/Alex
prog_test.go:11: Alex
--- FAIL: TestRunFatal (0.00s)
--- FAIL: TestRunFatal/Alex (0.00s)
FAIL
Program exited.
This output is from slightly modified version of my test
=== RUN TestRunFatal
=== RUN TestRunFatal/Alex
=== CONT TestRunFatal
prog_test.go:11: Alex
=== CONT TestRunFatal/Alex
testing.go:1343: test executed panic(nil) or runtime.Goexit: subtest may have called FailNow on a parent test
--- FAIL: TestRunFatal (0.00s)
--- FAIL: TestRunFatal/Alex (0.00s)
FAIL
Program exited.
Perhaps I don't understand how tests work. But I was surprised and confused by the
testing.go:1343: test executed panic(nil) or runtime.Goexit: subtest may have called FailNow on a parent test
error message. I also tried reading testing.FailNow documentation at
Document in https://pkg.go.dev/testing#T.Run
Run runs f as a subtest of t called name. It runs f in a separate goroutine and blocks until f returns or calls t.Parallel to become a parallel test.
https://go.dev/play/p/BtIQcyQJYxR A new goroutine is opened in the code t.Run() of. In this goroutine, TestRunFatal's t.Fatal() calls TestRunFatal's t.FailNow(). This is expected behavior.
That's right, this behavior is expected. The test captures t from the parent test and fails it from the subtest, which isn't allowed (because it's not on that test's goroutine).
On the topic of error messages and documentation, I think this could probably be a bit clearer, or have an example. I wonder if any of the go.dev tutorials point this out.
Activity
qiulaidongfeng commentedon Jan 29, 2023
Document in https://pkg.go.dev/testing#T.Run
Run runs f as a subtest of t called name. It runs f in a separate goroutine and blocks until f returns or calls t.Parallel to become a parallel test.
Document in https://pkg.go.dev/testing#T.Fatal
Fatal is equivalent to Log followed by FailNow.
https://go.dev/play/p/BtIQcyQJYxR A new goroutine is opened in the code t.Run() of. In this goroutine, TestRunFatal's t.Fatal() calls TestRunFatal's t.FailNow(). This is expected behavior.
alexbrainman commentedon Jan 29, 2023
Maybe you are correct @qiulaidongfeng .
Alex
mknyszek commentedon Jan 30, 2023
That's right, this behavior is expected. The test captures
tfrom the parent test and fails it from the subtest, which isn't allowed (because it's not on that test's goroutine).mknyszek commentedon Jan 30, 2023
On the topic of error messages and documentation, I think this could probably be a bit clearer, or have an example. I wonder if any of the go.dev tutorials point this out.