RS.CLIPPY.TEST_ATTR_IN_DOCTEST

Presence of `#[test]` in code examples

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

What it does

Checks for #[test] in doctests unless they are marked with either ignore, no_run or compile_fail.

Why is this bad?

Code in examples marked as #[test] will somewhat surprisingly not be run by cargo test. If you really want to show how to test stuff in an example, mark it no_run to make the intent clear.

Examples

/// An example of a doctest with a `main()` function
///
/// # Examples
///
/// ```
/// #[test]
/// fn equality_works() {
///     assert_eq!(1_u8, 1);
/// }
/// ```
fn test_attr_in_doctest() {
    unimplemented!();
}