getting cross-package coverage in golang without init() running

Viewed 93

I have inherited a very large, very old golang codebase. I'm trying to get coverage stats and most of the tests are testing across packages.

If I run go test ./... the tests pass.

If i run go test -coverpkg=./... ./... then the tests fail because all the the init() functions are executed during the tests. (It's failing in a bunch of cobra cmd that don't even have tests). The init() do things that cause the tests to fail.

Is there a way to get the init() to not happen when collecting coverage just like a normal test run?

0 Answers
Related