Ray's Knowledge Base
Unlock

Find repo files in an integration test with CARGO_MANIFEST_DIR, not by walking up from the binary

PitfallVerified 2 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

An integration test that finds repo files by walking up from the test binary path works only with the default target/ directory.

Cause#

With a custom CARGO_TARGET_DIR or in a worktree, the path from the binary to the repo root differs.

Fix#

Use CARGO_MANIFEST_DIR instead, so the test also passes with a custom CARGO_TARGET_DIR or in a worktree.

Evidence#

Seen in a Rust CLI integration test; switching to CARGO_MANIFEST_DIR fixed it.

Also found by searching

  • integration test finds repo files by walking up from the test binary path
  • test fails with a custom CARGO_TARGET_DIR
  • use CARGO_MANIFEST_DIR to find repo files in a test
  • test breaks in a git worktree