Description
Hi there,
I'm trying to use ReTest with an existing codebase, primarily for the parallel execution of tests. This codebase uses logging extensively, and the tests themselves may also include logging statements.
Obviously, logging naively can be problematic for threaded or distributed settings, as the outputs of multiple things at the same time might trample over each other. Hence, I'd like to do something like this (which is a minor edit of the example in the docs):
module MyPackageTests
using MyPackage, ReTest
using Logging, Distributed
id = myid()
rm("log-$(id).txt"; force=true)
io = open("log-$(id).txt", "w+")
# Create a logger and set it as the global logger for this process.
logger = SimpleLogger(io)
global_logger(logger)
@testset "more greet" verbose=true begin
@testset "concatenation" verbose=true begin
@info("Hello from worker $(id), in `concatenation`.")
@test MyPackage.greet()^2 == "Hello World!Hello World!"
end
# ...
end
# ...
# Close the file and flush remaining writes.
close(io)
end # module
If I run this in the REPL as follows:
julia> using Distributed; addprocs(2, exeflags="--project=$(Base.active_project())"); @everywhere include("test/MyPackageTests.jl"); MyPackageTests.runtests();
...
The files get created, the tests are run and pass, but nothing is printed. If I use println(global_logger())
in the test module after setting the logger I get the expected result. But it seems like @testset
silently consumes/captures the output from logging and prevents anything being written to a file.
I would say this is a significant enhancement - lots of code may use logging, and setting up a simple logger this way would allow that functionality to be at least partially retained with minimal changes to the majority of the codebase (just some small set-up for a logger per module).
I am running with the latest version of ReTest as of writing (0.3.2) and on an Ubuntu VM (Focal Fossa, 20.04.3 LTS).