pola-rs/polars · error
CARGO_MANIFEST_DIR not set
Error message
CARGO_MANIFEST_DIR not set
What it means
The test helper get_file_path panics via expect() because the CARGO_MANIFEST_DIR environment variable is not set. This variable is set by cargo during `cargo test` but is absent when tests run through other harnesses or environments. It is used to locate the sample foods1.ipc file relative to the crate.
Solutions
- Run the tests via `cargo test -p polars-arrow` so cargo sets CARGO_MANIFEST_DIR automatically.
- If invoking the binary directly, export CARGO_MANIFEST_DIR=<path to crates/polars-arrow> before running.
- Replace the env lookup in the test with a compile-time path such as env!("CARGO_MANIFEST_DIR") or an absolute path fixture.
Example fix
// before
let polars_arrow = std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
// after
let polars_arrow = env!("CARGO_MANIFEST_DIR"); Defensive patterns
Strategy: validation
Validate before calling
if std::env::var("CARGO_MANIFEST_DIR").is_err() {
panic!("Run tests via `cargo test` or set CARGO_MANIFEST_DIR to the polars-arrow crate path");
} Prevention
- Always run crate tests with `cargo test`, never the raw test binary
- Set required env vars explicitly in CI before invoking test harnesses
- Prefer env!() (compile-time) over runtime env lookups for test fixtures
When it happens
Trigger: Running the polars-arrow IPC tests (test_file_flight_simple, test_file_flight_amortized) outside of a cargo-managed invocation, e.g. via a custom test runner, IDE debugger, or a stripped environment where std::env::var("CARGO_MANIFEST_DIR") returns Err.
Common situations: Running tests through tools that sanitize env vars (docker with minimal env, `env -i`), executing the compiled test binary directly instead of `cargo test`, or CI systems that invoke the test executable without cargo.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/9c181163af06bfdf.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-arrow/src/io/ipc/read/flight.rs:417
if option_recordbatch.is_some() {
return Ok(option_recordbatch);
}
}
Ok(None)
}
}
#[cfg(test)]
mod test {
use std::path::{Path, PathBuf};
use tokio::fs::File;
use super::*;
use crate::record_batch::RecordBatch;
fn get_file_path() -> PathBuf {
let polars_arrow = std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
Path::new(&polars_arrow).join("../../py-polars/tests/unit/io/files/foods1.ipc")
}
fn read_file(path: &Path) -> RecordBatch {
let mut file = std::fs::File::open(path).unwrap();
let md = crate::io::ipc::read::read_file_metadata(&mut file).unwrap();
let mut ipc_reader = crate::io::ipc::read::FileReader::new(&mut file, md, None, None);
ipc_reader.next().unwrap().unwrap()
}
#[tokio::test]
async fn test_file_flight_simple() {
let path = &get_file_path();
let mut file = tokio::fs::File::open(path).await.unwrap();
let stream = into_flight_stream(&mut file).await.unwrap();
let mut c = FlightstreamConsumer::new(Box::pin(stream)).await.unwrap();
let b = c.next_batch().await.unwrap().unwrap();View on GitHub (pinned to fe841f959e)