I've previously used #[traced_test] with no issues, but, in a current project using [tokio_test] along with [serial], tests fail with this error:
Could not set global tracing subscriber: SetGlobalDefaultError("a global default trace dispatcher has already been set")
No test anywhere in the project is setting any global default trace dispatcher.
I can't find a bit about this on the web, and I have been unable to track it down to a minimal reproducible case.
Here's the odder part:
- If I run a single test without
--nocapture
, the test works (no above error) - but there is no tracing output
- If I run a single test with
--nocapture
, the error occurs
- If I run all tests, it happens, with or without
--nocapture
Are you talking about combining serial-test
with tracing-test
? I just tried it using the latest versions of all crates (and tokio's full
feature), and it's working in a minimal demo (with and without --nocapture
):
fn main() {
println!("Hello, world!");
}
#[cfg(test)]
mod tests {
use serial_test::serial;
use tracing::info;
use tracing_test::traced_test;
#[traced_test]
#[tokio::test]
#[serial]
async fn test_one() {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
info!("one");
}
#[traced_test]
#[tokio::test]
#[serial]
async fn test_two() {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
info!("two");
}
}
As expected, each test pauses for 1 second before printing ok
. And if I make either panic, I see the tracing info log.
Your best bet is going to be coming up with a minimal repro. treereduce-rust
might be able to help automate some of that.
As I said, tokio-test is in the mix too.
Non-async tests work fine.
And I've had it work in the past, too.
It no longer works.
I am certain there is an issue. I was hoping someone else had run into it and had some ideas.
I'm also using tokio::test
in the code above, and there is no problem there.
I'm trying to say that I am unable to reproduce your results, and you might have to do some work to minimize a reproduction. Especially since you haven't come across anyone else with similar reports.
I now know that's the case. 
Yes, I'll have to come up with a MRS. At some point.
For now, I think I'll create a new set of macros that wraps the tracing ones and adds println!.