Have your testing code in different files and use the kcov
arguments --exclude-path=./test
(for the integration tests) or --exclude-pattern=_test.rs
(if you move all your tests for foo.rs into foo_test.rs).
Another way is to use the kcov
argument --exclude-region='#[cfg(test)]:#[cfg(testkcovstopmarker)]'
and make sure that each file either only has tests at the end and no non-test code following it or adds the stop marker #[cfg(testkcovstopmarker)]
with the necessary unused definition after it to make rustc
happy. (kcov
finds the start and end string for a region anywhere in a line.)
(There is also the possibility to exclude lines based on a string they contain, but that won't work for excluding tests in Rust.)