-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cargo test does not capture stdout/stderr in tokio::spawn async blocks #1696
Comments
I think it is rust's bug, not tokio? Most probably using single threaded runtime or |
IIRC, I ran the same test with the |
That would be strange... I'd need to check it. |
I ran a similar test on both #[test]
fn std_println() {
use std::thread;
println!("This should be captured by the test runner.");
thread::spawn(move || {
println!("This should also be captured by the test runner.");
});
println!("Wait a little while...");
thread::sleep(Duration::from_millis(10));
println!("All of this text should have been captured.");
} #[test]
fn tokio_current_thread_println() {
use tokio::runtime::current_thread::Runtime;
let mut rt = Runtime::new().unwrap();
rt.block_on(async {
println!("This should be captured by the test runner.");
tokio::spawn(async {
println!("This should also be captured by the test runner.");
});
println!("Wait a little while...");
tokio::timer::delay_for(Duration::from_millis(10)).await;
println!("All of this text should have been captured.");
});
} |
Version
tokio = "=0.2.0-alpha.6"
Platform
Description
cargo test
captures logs from stdout/stderr by using an undocumented function pair that internally manipulates the wayprint!
and friends work. When running a test using the Tokio runtime, any uses of theprint!
family macros do not get captured.My actual tests have a more complex setup to allow running multiple async tests in parallel. But this minimal example demonstrates the issue.
Expected result:
Actual result:
When running without capture, you will see all output printed as expected:
The text was updated successfully, but these errors were encountered: