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
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.
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 normalfunc 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:
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.CC @mpvl as per https://dev.golang.org/owners
The text was updated successfully, but these errors were encountered: