Skip to content
Latchkey

Go test coverage profile write failure - Fix in CI

go test -coverprofile writes a single coverage file. When the target directory does not exist, is read-only, or multiple package runs collide on the path, the write fails and the run errors.

What this error means

A coverage run fails with cannot create coverprofile: open cover.out: no such file or directory or permission denied, or the profile ends up empty after a multi-package run. It means the path or write mode is wrong.

go
go test -coverprofile=reports/cover.out ./...
cannot create 'reports/cover.out': open reports/cover.out: no such file or directory

Common causes

Target directory missing or read-only

The coverprofile path points at a directory that does not exist or cannot be written.

Per-package profiles overwrite each other

Running coverage per package to the same file leaves only the last package, or collides mid-write.

How to fix it

Create the directory and write once

  1. Make the output directory and run coverage across all packages into one profile.
.github/workflows/ci.yml
mkdir -p reports
go test -coverprofile=reports/cover.out -covermode=atomic ./...

Use a writable path

  1. Write the profile to a path the job owns, such as the workspace root.
Terminal
go test -coverprofile=cover.out ./...

How to prevent it

  • Create the output directory before writing the profile.
  • Write one combined profile across ./... rather than per package.
  • Keep the profile path inside the writable workspace.

Related guides

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