0

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?

3
  • Hello, this article can help you? siciarz.net/24-days-rust-environment-variables Commented Oct 13, 2022 at 14:19
  • Yes, you can persist environment variables in your shell and your tests will see them. Do you not know how to do that? Commented Oct 13, 2022 at 14:58
  • I just can't. It says thread 'test_case1' panicked at 'called `Result::unwrap()` on an `Err` value: NotPresent', src/main.rs:170:22. Commented Oct 13, 2022 at 15:32

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.