How to Ignore Tests and Run Them Conditionally

Skip tests with #[ignore] and run them later using cargo test -- --ignored or --include-ignored flags.

Add the #[ignore] attribute to a test function to skip it during normal runs, then use cargo test -- --ignored to execute only those skipped tests.

#[test]
#[ignore]
fn expensive_test() {
    // code that takes an hour to run
}

// Run ignored tests only:
// cargo test -- --ignored

To run a specific ignored test by name, use:

cargo test -- --ignored expensive_test

To run all tests including ignored ones, use:

cargo test -- --include-ignored