I want to run a rust test with some env, like:
use std::env; #[test] fn test_case1() { env::var("ENV1").unwrap(); env::var("ENV2").unwrap(); } #[test] fn test_case2() { env::var("ENV1").unwrap(); env::var("ENV2").unwrap(); } ENV1=ABC ENV2=123 cargo test test_case1 But I want to only set these env once and I can reuse them in the shell, like:
ENV1=ABC ENV2=123 echo $ENV1 // ABC echo $ENV2 // 123 cargo test test_case1 // test_case1 will read ENV1, ENV2 then quit, cargo test test_case2 // test_case2 will read ENV1, ENV2 too How can I do it?
thread 'test_case1' panicked at 'called `Result::unwrap()` on an `Err` value: NotPresent', src/main.rs:170:22.