RS.CLIPPY.TESTS_OUTSIDE_TEST_MODULE

A test function is outside the testing module.

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: tests_outside_test_module. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Triggers when a testing function (marked with the #[test] attribute) isn't inside a testing module (marked with #[cfg(test)]).

Why restrict this?

The idiomatic (and more performant) way of writing tests is inside a testing module (flagged with #[cfg(test)]), having test functions outside of this module is confusing and may lead to them being "hidden".

Example

#[test]
fn my_cool_test() {
    // [...]
}

#[cfg(test)]
mod tests {
    // [...]
}

Use instead:

#[cfg(test)]
mod tests {
    #[test]
    fn my_cool_test() {
        // [...]
    }
}