-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A flag to unset all pre-existing variables #24
Comments
That's a good idea. Though I don't think we need a new flag, this can be done already today with something along the lines of: let vars_to_unset = std::env::vars().map(|(key, _value)| (key, None)).collect();
temp_env::with_vars(
[
vars_to_unset,
vec![("MY_VAR".to_string(), Some("my_value"))],
]
.concat(),
|| {
println!("vmx: env without pre-existing vars: {:?}", std::env::vars());
},
); Does that solve your problem? |
Calling But I agree it'll work if everyone is purely adding additional variables instead of unsetting some. |
If I understand it correctly, you would set the |
But that would force every tests to run the setup even if they don't necessarily need a clean environment. Any one test missing the setup && unset some variables in temp_env will cause the problem I described earlier. |
I have a draft here. Is that what you had in mind? I'm a bit hesitant about it, because this will also unset all of these variables and that may cause surprising effects in tests, for example backtraces not working properly within the tests because |
Yes it is, appreciate the work!
True, I didn't think about this before. It isn't just the behavior inside I think a better description of what Say we provide a method called temp_env::new(
|| {
for (key, var) in std::env::vars() {
temp_env::set_in_scope(key, None);
}
},
); |
It would make tests more reproducible.
The text was updated successfully, but these errors were encountered: