I have a workspace with several crates. I need to exclude a particular test.
I tried adding an environment variable check, but this doesn't work.  I guess cargo test filters out the environment variables.
// package1/src/lib.rs
// ...
#[cfg(test)]
mod tests {
    #[test]
    fn test1() {
        if std::env::var("CI").is_ok() {
            return;
        }
        // ...
    }
}
Then I tried passing the --exclude parameter with various options, but none of them work:
cargo test --workspace --exclude test1cargo test --workspace --exclude tests:test1cargo test --workspace --exclude tests::test1cargo test --workspace --exclude '*test1'cargo test --workspace --exclude 'tests*test1'cargo test --workspace --exclude package1This skips all of the tests in the package.cargo test --workspace --exclude 'package1*test1'
How can I run all workspace tests except one?
                        
Excluding a test
The help file by running
cargo test -- --helplists useful options:Regarding the
--aftertest, see:src/lib.rs
Runing the above with
cargo test -- --skip test_mulwill give the following output:Excluding a test within a specific package
If you want to exclude a specific test for package within a workspace, you can do so in the following way, replacing
my_packageandmy_testwith their appropriate names:Test all, but exclude
my_packageAnd then test
my_packageitself, with the specific test excluded by adding--skip my_test:For more options, see:
Excluding a test by default
Alternatively, you could add the
#[ignore]attribute to tests that should not run by default. You can still run them separately if you wish to do so:src/lib.rs
Running the tests using
cargo test -- --ignored:If you're using Rust >=
1.51and want to run all tests, including those marked with the#[ignore]attribute, you can pass--include-ignored.