Exclude Generated Code
Generated code — protobuf stubs, ORM models, wire boilerplate, vendored dependencies — inflates or distorts coverage numbers because it is not meaningful to test. This page explains how to exclude such files from coverage measurement while you wait for nolapse’s native exclusion feature.
Go Projects
Section titled “Go Projects”Workaround A: Build tags on generated files
Section titled “Workaround A: Build tags on generated files”Add a //go:build ignore tag to generated files. The Go toolchain skips these files entirely when running go test -cover:
//go:build ignore
// Code generated by protoc-gen-go. DO NOT EDIT.package mypkgThis is appropriate for files that are already annotated with // Code generated by .... Simply add the build tag at the top. Be aware this also prevents the file from being compiled in normal builds — only use it on files that are not imported by your main packages.
Workaround B: Use -coverpkg to specify packages explicitly
Section titled “Workaround B: Use -coverpkg to specify packages explicitly”Instead of measuring all packages with ./..., enumerate only the packages you care about:
go test -coverpkg=github.com/my-org/my-repo/pkg/...,github.com/my-org/my-repo/internal/... ./...This excludes any package not listed, including generated packages typically placed in gen/, pb/, or vendor/.
nolapse invokes go test -cover ./... internally. To pass custom flags, run go test separately and produce a coverage.out file, then point nolapse at it (coverage file input is a planned feature — for now, use build tags as the primary workaround).
Workaround C: Move generated code to a dedicated module
Section titled “Workaround C: Move generated code to a dedicated module”If your generated code is large enough to warrant it, move it to a separate Go module (e.g. gen/go.mod). nolapse’s --repo flag scopes coverage to a single module root, so the generated module is automatically excluded when you run nolapse run --repo . from the main module root.
Python Projects
Section titled “Python Projects”Workaround: .coveragerc with omit patterns
Section titled “Workaround: .coveragerc with omit patterns”Create a .coveragerc file in your repo root (or component root for monorepos):
[run]omit = */migrations/* */generated/* */vendor/* *_pb2.py *_pb2_grpc.py setup.py conftest.pypytest-cov reads .coveragerc automatically. The omit patterns are glob patterns relative to the source root. You can also configure this in pyproject.toml:
[tool.coverage.run]omit = [ "*/migrations/*", "*/generated/*", "*_pb2.py",]nolapse invokes pytest --cov internally, which respects the coverage configuration file. After adding the omit patterns, re-initialise the baseline to capture the corrected coverage number:
nolapse init --repo . --lang python --forcegit add .audit/coverage/baseline.mdgit commit -m "chore: refresh baseline excluding generated files"What Is Coming in the Native Exclusion Feature
Section titled “What Is Coming in the Native Exclusion Feature”The planned exclusions block in nolapse.yaml will look like this:
lang: gowarn_threshold: 0.5fail_threshold: 1.0exclusions: paths: - "gen/**" - "vendor/**" - "**/*_pb2.py"Once implemented, nolapse will apply these exclusions before computing the coverage delta, without requiring changes to the test runner invocation.
See Also
Section titled “See Also”- nolapse.yaml Reference — full configuration schema
- Exclusions Config — exclusions configuration (planned)
- Go Language Reference — Go-specific coverage details
- Python Language Reference —
.coveragercand pytest-cov details