On Thursday, January 30, 2020 at 11:03:04 PM UTC-8, Craig Rodrigues wrote: > > > > On Thursday, January 30, 2020 at 10:06:36 PM UTC-8, Ian Lance Taylor wrote: >> >> On Thu, Jan 30, 2020 at 9:43 PM Craig Rodrigues <crod...@gmail.com> >> wrote: >> > I see here that this might be related: >> https://golang.org/doc/go1.13#testing >> > >> > Testing flags are now registered in the new Init function, >> > which is invoked by the generated main function for the test. >> > As a result, testing flags are now only registered when >> running >> > a test binary, and packages that call flag.Parse during >> package >> > initialization may cause tests to fail. >> > >> > But I'm not sure how to move forward to get back the behavior from go >> 1.12. >> >> That could well be the problem. If so, the solution is to not call >> flag.Parse from an init function. >> > > > Ah OK! > > So my_test.go , and every test file in my codebase has: > > func init() { > ParseFlags() > } > > which calls flag.Parse for a bunch of framework-specific test flags. > > How should I restructure this so that I get the "-test.XXX" flags > generated in the binary, > like I did with go 1.12? >
This change in *go test* seems due to this: https://github.com/golang/go/issues/21051 https://go-review.googlesource.com/c/go/+/173722/ so for my function: func init() { ParseFlags() } I went in the ParseFlags() function and removed a call to flag.Parse() as suggested by Ian (thanks for that suggestion!). That seemed to fix things for me. Will this be guaranteed to work in future go versions, or could this behavior change if something else changes in the internals of go test? -- Craig -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/bf1c9a89-036d-4aa4-b9a0-9ef60e15dd90%40googlegroups.com.