Go test "no required module provides package" - Fix in CI
A test file imports a package - often a test-only helper like testify - that no module in go.mod provides. go test fails the same way a build would, before any test runs.
What this error means
go test fails with no required module provides package X; to add it: go get X, naming a package used only in _test.go files. It means a test dependency was imported without being added to go.mod.
app/store_test.go:8:2: no required module provides package github.com/stretchr/testify/assert;
to add it:
go get github.com/stretchr/testify/assertCommon causes
Test-only import not required
A package used solely in tests was imported but go mod tidy never added it to go.mod.
tidy run without test imports considered
A partial tidy or an older Go did not record a test-only dependency.
How to fix it
Add the test dependency and tidy
- Run go get for the test package or go mod tidy to capture test imports.
- Commit go.mod and go.sum.
go get github.com/stretchr/testify@latest
go mod tidyGuard tidiness in CI
- Run go mod tidy and fail if go.mod or go.sum changes, catching missing test deps.
go mod tidy
git diff --exit-code go.mod go.sumHow to prevent it
- Run
go mod tidyafter adding any test import. - Stage go.mod and go.sum together.
- Add a tidiness guard to CI so missing test deps fail early.