R testthat package: How can I see output from message() when using test_file()

r, testthat

Solution

You can't do this, at least not without modifying the source code of `testthat`. This is the part that runs the code of the test: https://github.com/hadley/testthat/blob/0af22cfc7c7f6b13b02537f0d37d96d72d8a98b7/R/test-that.r#L65 If you remove the `suppressMessages` from the `test_code` function, then the messages will be displayed.

Btw. `testthat` does not capture standard output or error AFAIK, so if you write to it using `cat` or some other way, that will also displayed.

Problem

I am using the excellent testthat package in R. My issue is that I cannot see any output from the message() function in the code being tested when using test_file. for example, say I have following code in a file called test_message.R ``` f <- function() { message ("Message: Hello world") cat ("Cat: Hello world\n") return (1) } test_that ("message shows up", { expect_equal(f(), 1) }) ``` I run test_file as follows and get the output below ``` > test_file("test_message.R") Cat: Hello world . ``` So I am not seeing the text from message(). However, when I run the code on its own I do see it: ``` > f() Message: Hello world Cat: Hello world [1] 1 ``` I know that by default, message() writes to stderr and cat writes to stdout and I'm guessing that test_file "intercepts" stderr to test for the text in warnings and errors. Is there any way I can configure things so I see message() text on the console?

Original source