Skip to content
Latchkey

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

  1. Point -coverpkg at packages the tests actually exercise, commonly the whole module.
Terminal
go test -coverpkg=./... -coverprofile=cover.out ./...

Verify the pattern matches

  1. 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 list before wiring it into CI.
  • Keep the tested set and the coverage set consistent.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →