How to do debug prints in async tests?

I have a binary with Axum server, and want to test if there are deadlocks with RwLock. But debug prints aren't visible in the shell.

How to make them be printed? (In all docs I saw, there's no such issue: println from a thread does print.)

Maybe threads are to blame. I use them to guarantee requests come in parallel (no idea how to do this in pure async).

async fn main() {
    let app = Router::new().route("/query/", get(handle_read)).with_state(...);
    let listener = tokio::net::TcpListener::bind("").await.unwrap();
	println!("running the server at {addr}");
	axum::serve(listener, app).await.unwrap();

async fn handle_read(Path (_): Path<String>, State(ast): State<AppState2>) -> Result<(HeaderMap, String), (StatusCode, String)> {
	//let mut t = Timer::new();
	println!("read: got request");
	println!("read: replying");
	Ok((headers, body))
mod mytests {
    async fn tttt() {
        let mut threads: Vec<JoinHandle<()>> = vec![];
        // server
        threads.push(spawn(|| {
            println!("server thread: starting");

        // read request 1
        threads.push(spawn(|| {
            println!("read thread: making request");
            let resp = reqwest::blocking::get("http://localhost:8833/query/").unwrap().text().unwrap();
            println!("{:?}", resp);

Are you looking for cargo test -- --nocapture? Link to docs.



I figured out why it wasn't printing with panic(): the main thread would panic immediately, before other ones could print anything.