I can't see how to store the test logging output into a file. I have many tests running, all of which may generate some output which I may need for debugging and which may be useful to scrape with tools. For example, I can't load the failing test messages into an LLM assistant by pointing them at the test output file. But all the output is dumped to the terminal, and the output from all the tests is "mixed up" in the single stream, which is fine for a person but rubbish for tooling. Please could we have an option for cargo test
to write out all the test output into the target directory somewhere?
Are you using cargo test -- --nocapture
when you get this mixed output? If so, use cargo test -- --show-output
instead. This will group the output by test while still showing all output rather than only failures’ output.
If the output is being printed regardless of command line options, then you should replace your uses of std::io::stdout()
with println!()
to interact with the test output capture system. (Or, write to a file explicitly, if you want.)
The standard test harness also has a --logfile
option, which I have never used but you might like.
The --logfile option seems to just log the pass/fail status of tests, not output of tests.
Unfortunately, --logfile
doesn't open the file for appending, so each test target overwrites it. E.g. Doc-tests are the only thing that will appear since Cargo runs them last by default.
It has the same cause as Running cargo test -- --help
doesn't produce expected output · Issue #10392 · rust-lang/cargo
Some shell magic can simulate it:
cargo test --workspace -- --show-output 2>&1 | tee test.log
Thanks. It doesn't really solve my problem of wanting a machine-readable version of the test output that I can then pass into downstream tools, or compare between runs, or feed into an LLM agent to help me with development.