Skip doctest from command line

Is there a way to skip doctests when running cargo from the command line.

My project tests have got too slow for my git pre-commit hook. I can avoid running some of the longer running tests with --skip. But the doctests are actually the slowest part of test execution for me (not sure why, they are not very intense). I'd like to be able to not run them without removing them.

1 Like

This command will run library unit tests (--lib), binary unit tests (--bins), and integration tests (--tests), but not doctests:

cargo test --lib --bins --tests

You can omit arguments that don't apply to your project. For example, if your only tests are part of your library crate, you can just run cargo test --lib.

Every doctest is compiled into a separate binary, so doctests have a lot of compiler and linker overhead.

Thank you, that's very useful indeed. It brings my tests from 10secs down to 0.2.

I guess the doctests are compiled everytime? In my hands they are slow even if the source code hasn't changed at all.