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: Short() does not work in TestMain() #9825
TestMain is executed before flag.Parse in (*testing.M).Run.
I think this is intentional, because it provides a way to modify the
command line arguments. I you want testing.Short(), then you
should call flag.Parse() manually in TestMain.
In conclusion, I think a docs clarification is needed, it's not a bug.
I really would like to see changed as well.
I was planning to use testMain as:
funcTestMain(m*testing.M) {
// Reset test db before running test.// The schema is only imported once for all testif!testing.Short() {
fmt.Println("Initializing test DB for integration test (disable with `go test -short`)")
initTestDB()
}
os.Exit(m.Run())
}
Activity
minux commentedon Feb 10, 2015
TestMain is executed before flag.Parse in (*testing.M).Run.
I think this is intentional, because it provides a way to modify the
command line arguments. I you want testing.Short(), then you
should call flag.Parse() manually in TestMain.
In conclusion, I think a docs clarification is needed, it's not a bug.
[-]testing: Short() not works on TestMain()[/-][+]testing: Short() does not work in TestMain()[/+]hraban commentedon Mar 9, 2015
Please include that testing.Verbose() also doesn't work in TestMain. Came here to post an issue about it, but now I see it's by design.
gravis commentedon Mar 16, 2015
I really would like to see changed as well.
I was planning to use testMain as:
And initTestDB() is always run :(
minux commentedon Mar 16, 2015
I don't think this is going to change.
If you want to use testing.Verbose or testing.Short, call flag.Parse in
TestMain before using them.
gravis commentedon Mar 16, 2015
Ok, thanks for the info
minux commentedon Mar 16, 2015
gravis commentedon Mar 16, 2015
👍 👍