Let say i have this test function, my dotenv work fine except for the username variable. it keeps pulling my shell USERNAME variable.
my question is how do i make .env override the shell variable
#[tokio::test]
async fn test_function() {
dotenv::dotenv().ok();
let host = env::var("HOST").unwrap();
let port = env::var("PORT").unwrap();
let username = env::var("USERNAME").unwrap(); // <- does not read from the .env file
let password = env::var("PASSWORD").unwrap();
}
Seems like you can't. https://github.com/dotenv-rs/dotenv/issues/12
There are a couple other issues/PRs, but as of now there is no API to do what you want as far as I can tell. If you control the .env file I would recommend prefixing the keys with the name of your program or something like that to avoid conflicts.