Go test "-coverpkg" conflict / no packages - Fix in CI
The -coverpkg flag selects which packages count toward coverage. A pattern that matches nothing, or one combined with -coverprofile across multiple packages incorrectly, makes go test fail or warn out.
What this error means
A coverage run fails with no packages being tested depend on matches for pattern X, cannot use -coverpkg with ..., or warns that the profile covers no statements. It means the -coverpkg pattern is wrong or mismatched with the test scope.
go
go test -coverpkg=./internal/... -coverprofile=cover.out ./cmd/...
warning: no packages being tested depend on matches for pattern ./internal/...Common causes
Pattern matches no tested package
The -coverpkg pattern does not intersect the packages under test, so nothing is instrumented.
coverpkg and coverprofile scopes disagree
The tested set and the coverage set are inconsistent, producing an empty or rejected profile.
How to fix it
Use a pattern that resolves
- Point -coverpkg at packages the tests actually exercise, commonly the whole module.
Terminal
go test -coverpkg=./... -coverprofile=cover.out ./...Verify the pattern matches
- List packages matching the pattern before relying on it for coverage.
Terminal
go list ./internal/...How to prevent it
- Prefer
-coverpkg=./...unless you deliberately scope coverage. - Verify the pattern with
go listbefore wiring it into CI. - Keep the tested set and the coverage set consistent.
Related guides
Go test coverage profile write failure - Fix in CIFix Go test "-coverprofile" write failures in CI - go test could not write the profile, often a missing direc…
Go test "no required module provides package" - Fix in CIFix Go "no required module provides package" during go test in CI - a test imports a package no require provi…
Go "panic: test timed out after 10m0s" - Fix in CIFix Go "panic: test timed out after 10m0s" in CI - a test exceeded the default timeout, usually a hang or a s…