Feature-based conditional excludes test from cargo test inventory

When I want to gate a whole test by a feature, I use conditional compilation, like this:

contents of some_test.rs

#![cfg(features = "some_feature")]

fn some_test() {
    assert_eq!(1, 1);

However, this seems to remove the test from Cargo's test inventory, even when the feature is enabled.

When I run cargo test --features some_feature I can verify the feature is conditionally compiled, but the test is never run, nor even found.

     Running tests/some_test.rs (target/debug/deps/some_test-c832248c7dba795f)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

This seems like something others would have encountered, but I haven't been able to turn up anyone describing precisely this issue.

Is this a known issue?


Shouldn't it be #![cfg(feature = "…")], singular?


D'oh!!! :person_facepalming: Explains why nobody else is talking about it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.