env-lock

Crates.ioenv-lock
lib.rsenv-lock
version0.1.2
sourcesrc
created_at2024-08-15 14:10:53.355355
updated_at2024-08-19 13:53:48.487749
descriptionSet and lock environment variables for tests
homepage
repositoryhttps://github.com/LucasPickering/env-lock
max_upload_size
id1338821
size13,858
Lucas Pickering (LucasPickering)

documentation

README

env-lock

Test CI crates.io docs.rs

A process's environment is a form of global mutable state. In Rust, tests are run in a shared process. This means tests that modify environment variables can inadvertently affect each other. env-lock provides an interface to safely modify and lock the process environment, to prevent simultaneous access.

use std::env;

let var = "ENV_LOCK_TEST_VARIABLE";
assert!(env::var(var).is_err());

let guard = env_lock::lock_env([(var, Some("hello!"))]);
assert_eq!(env::var(var).unwrap(), "hello!");
drop(guard);

assert!(env::var(var).is_err());
Commit count: 0

cargo fmt