-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Labels
loggingThe logging frameworkThe logging frameworktestThis change adds or pertains to unit testsThis change adds or pertains to unit tests
Description
(See the Discourse discussion here: https://discourse.julialang.org/t/test-logs-behavior-when-using-with-logger/80239)
@test_logs works by creating a TestLogger and wrapping its argument in a with_logger block. The problem with this is that if the argument itself already uses a with_logger block, this inner block receives all log statements without passing them on to the TestLogger. Therefore, in such situations @test_logs will fail, even if the underlying code works.
At minimum this should be mentioned in the documentation. However, it would be good to provide a work-around for this. Two suggestions that came to my mind are:
- Create a
@test_outputmacro to intercept STDOUT. This would be directly equivalent to@test_warn. The advantage would be that this could also be used to test screen output other than log calls. The disadvantage is that having to revert to intercepting STDOUT hides some of the details of log calls. - Alternately, one might be able to dig into Base.CoreLogging to provide a way to override local loggers when using
@test_logs. This would be the cleanest solution from a user's perspective (@test_logsdoes what you expect even when using local loggers), but may be tricky/messy to implement.
Metadata
Metadata
Assignees
Labels
loggingThe logging frameworkThe logging frameworktestThis change adds or pertains to unit testsThis change adds or pertains to unit tests