Attribute Macro env

Source
#[env]
Expand description

Run test case when the environment variable is set.

#[cfg(test)]
mod tests {

    // PWD environment variable exists
    #[test_with::env(PWD)]
    #[test]
    fn test_works() {
        assert!(true);
    }

    // NOTHING environment variable does not exist
    #[test_with::env(NOTHING)]
    #[test]
    fn test_ignored() {
        panic!("should be ignored")
    }

    // NOT_SAYING environment variable does not exist
    #[test_with::env(PWD, NOT_SAYING)]
    #[test]
    fn test_ignored_too() {
        panic!("should be ignored")
    }
}

or run all test cases for test module when the environment variable is set.

#[test_with::env(PWD)]
#[cfg(test)]
mod tests {

    #[test]
    fn test_works() {
        assert!(true);
    }
}