Capturing stdout/stderr from Pkg.test

Is it possible to call Pkg.test and make it capture all the output from the test process?

I’m trying something like the code below, but the tests run in a sandbox so I guess that’s why I’m unable to capture the output.

function fetch_logs(io)
    buff = Vector{UInt8}(undef, bytesavailable(io))
    readbytes!(io, buff)
    return String(buff)

rd, wr = redirect_stdout()
write(log_file_io, fetch_logs(rd))

I guess the only way to do this currently is to do something like:

run(pipeline(`julia --project=$pkgdir -e 'import Pkg; Pkg.test(test_args = [ "test-args" ])'`, stdout="out.txt", stderr="errs.txt"))