You may try to use one of several workarounds.
First is to use println
when crate is compiled for test like this.
#[cfg(not(test))]
use log::{info, warn}; // Use log crate when building application
#[cfg(test)]
use std::{println as info, println as warn}; // Workaround to use prinltn! for logs.
To prevent cargo
from silencing tests stdout, run tests like this
$ cargo test -- --nocapture
Another elegant workaround is to use test-log crate
#[test_log::test] // Automatically wraps test to initialize logging
fn hello_log_tests() {
// ...
}
To use dependency (such as env_logger
mentioned in error message) for tests include it in dev-dependencies
section
[dev-dependencies]
env_logger = "*"