I have a number of tests defined inside some of my modules with:
#[cfg(test)]
mod tests {
...
and a number of tests found inside my /tests directory. All of these happen to need a common function called get_local() that I have put inside a utils module
+src
|-lib.rs
|-utils.rs
|-...
+tests
|_common.rs
Now since this function is only used in case I run tests I thought I should add a #[cfg(test)] above it.
#[cfg(test)]
pub fn get_local() -> SomeResult { ... }
and then I make sure it is inside lib.rs:
pub mod utils;
When I try using the function in tests/common.rs though:
use my_crate::utils::get_local;
and run the tests with the test command I get the error: no get_local in utils. This error only goes away if I remove #[cfg(test)] from the declaration of get_local. Why does this happen?