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: clarify that flag.Parse is called before any tests run #38952
Suppose I'm a new Go developer, and I want to write a test that uses a flag. I know I have to call flag.Parse in a normal func main program to use flags, so by default, I assume that the same applies to tests.
If I look at the testing docs, here is the only mention of flag parsing I can find:
When TestMain is called, flag.Parse has not been run. If TestMain depends on command-line flags, including those of the testing package, it should call flag.Parse explicitly.
So it's clear that, if I want my TestMain to use flags, I need to parse them there. That's fine.
However, what if I don't want or need a TestMain? It's not clear at what point the flag parsing happens, or if it happens at all before the tests and benchmarks run.
In practice, flag parsing happens in testing.M.Run if it hasn't happened already. I think the docs should clarify that.
Activity
gopherbot commentedon May 8, 2020
Change https://golang.org/cl/232806 mentions this issue:
testing: tests and benchmarks can assume flag.Parsed