rust-lang-nursery / lazy-static.rs

A small macro for defining lazy evaluated static variables in Rust.
Apache License 2.0
1.91k stars 111 forks source link

`cargo test` failed after I created a variable with `lazy_static!`. #118

Closed hxingpax closed 6 years ago

hxingpax commented 6 years ago

Every test case involved with the lazy_static! variable are poisioned and failed.

How to avoid such a situation.

KodrAus commented 6 years ago

@hxingpax The lazy_static! can get poisoned if it panics during initialization. Since test cases are all executed in a single runtime all test cases will observe the same lazy_static!.

hxingpax commented 6 years ago

Thanks, I removed that one. Now I go with lazy_static very carefully.

KodrAus commented 6 years ago

@hxingpax Yeh, there are definitely some pitfalls like this to be careful of with global state like lazy_static.

If you are hitting a panic somewhere in initialization though one of your tests should have a more descriptive error message that first caused the failure.