-
@test_logs
tests for log output
-
@test_nowarn
tests that stdout
is empty (and, despite the name, isn’t meant strictly for the @warn
macro)
How to test whether stdout
is empty as well? How to test whether an expression didn’t output anything (log messages or anything else) to stderr
and stdout
?
I tried to redirect stdout
and stderr
to IOBuffer
s, but it didn’t work.
1 Like
Could you post a simple code example showing what you have tried?
The last link in my post is a link to the example, but here it is again. I tried to redirect_stdio
to some IOBuffer
s:
buf_stdout, buf_stderr = IOBuffer(), IOBuffer()
redirect_stdio(stdout=buf_stdout, stderr=buf_stderr, stdin=devnull) do
@info "Hello!"
end
I then planned to test whether length(take!(buf_stdout)) == 0
(and similarly for buf_stderr
).
However, it produced this error:
MethodError: no method matching (::Base.RedirectStdStream)(::IOBuffer)
Yes, it looks like you have hit an issue that has been around for a long time.
The only solution I can think of is to redirect to a temporary file or a socket, but of course that is not very elegant and I could imagine that you have seen that solution already. The other solution would be to make a pull request fixing this in the next release of Julia