Is it possible to "report back" to the test framework that a test has been ignored for a reason?
We have a client library that has a few tests that require a (test) server. If there's no server available, I want a discreet ignored (server is not running) message rather than an error dump.
I saw some brainstorming somewhere a while back that had some kind of predicate function used to determine if a test should run. IIRC it looked something like this:
tracing logs aren't captured by libtest per default. So a quick and dirty workaround (that you could abstract into a self-made #[skip] attribute macro) would be to emit a warning when the test is skipped:
#[test]
fn test_requiring_server() {
tracing_subscriber::fmt()
.event_format(tracing_subscriber::fmt::format().without_time())
.with_target(false)
.init();
#[tracing::instrument]
fn test_requiring_server() {
tracing::warn!("skipped function because predicate was true");
}
fn predicate() -> bool {
true
}
if predicate() {
test_requiring_server();
return;
}
// here the test code
assert!(true);
}
Output:
WARN test_requiring_server: skipped function because predicate was true
test test_requiring_server ... ok