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

user2793761

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?

Gabor Csardi

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I see when a package was released/updated using `apt`?

From Dev

r devtools test() errors but testthat test_file() works

From Dev

r devtools test() errors but testthat test_file() works

From Dev

R: Problems with testthat test_file() within local environment

From Dev

How to test an installed package with testthat?

From Dev

How can I see console.log output in a node express app when using nginx + passenger

From Dev

How can I see printf output when evaluating an expression using the `expr` command in lldb?

From Dev

How can I see when package has been upgraded?

From Dev

How can I see the json coming from the client when using Spring-MVC?

From Dev

Using the python quickfix package, how can I send a TestRequest message?

From Dev

how do I change the color of output of a table created by using function called "datatable" from DT package in R?

From Dev

How can I see the command string when using MySqlCommand parameters?

From Dev

How can I see a timestamp for when a command was executed using history?

From Dev

How can I see dmesg output as it changes?

From Dev

How can I see each of tables from database in R?

From Dev

Why I can't see the debug output when I run a test in Visual Studio 2012?

From Dev

Why I can't see the debug output when I run a test in Visual Studio 2012?

From Dev

How can I set wide screen when using R markdown with html output?

From Dev

How can I change PDF output font from within the YAML header when using Pandoc on Markdown?

From Dev

How can I make the application package available to the tests, when using py.test?

From Dev

How does FB messenger removes push notification from iOS app when I see the message on FB Desktop?

From Dev

How can I see which versions (platform/version/abi) of a package are available using pip3?

From Dev

Why can't I see any output when executing a windows batch file with VS code tasks

From Java

When using BuildKit with Docker, how do I see the output of RUN commands?

From Dev

How do I see g++ compiler output when using Jam?

From Dev

When using Swift Package Manager how can I generate an Xcode project file for development

From Dev

How to call batch from powershell so I can see realtime output in powershell console

From Dev

UdpSocket.recv_from fails with "end of file" but I can see the incoming package in Wireshark

From Dev

UdpSocket.recv_from fails with "end of file" but I can see the incoming package in Wireshark

Related Related

  1. 1

    How can I see when a package was released/updated using `apt`?

  2. 2

    r devtools test() errors but testthat test_file() works

  3. 3

    r devtools test() errors but testthat test_file() works

  4. 4

    R: Problems with testthat test_file() within local environment

  5. 5

    How to test an installed package with testthat?

  6. 6

    How can I see console.log output in a node express app when using nginx + passenger

  7. 7

    How can I see printf output when evaluating an expression using the `expr` command in lldb?

  8. 8

    How can I see when package has been upgraded?

  9. 9

    How can I see the json coming from the client when using Spring-MVC?

  10. 10

    Using the python quickfix package, how can I send a TestRequest message?

  11. 11

    how do I change the color of output of a table created by using function called "datatable" from DT package in R?

  12. 12

    How can I see the command string when using MySqlCommand parameters?

  13. 13

    How can I see a timestamp for when a command was executed using history?

  14. 14

    How can I see dmesg output as it changes?

  15. 15

    How can I see each of tables from database in R?

  16. 16

    Why I can't see the debug output when I run a test in Visual Studio 2012?

  17. 17

    Why I can't see the debug output when I run a test in Visual Studio 2012?

  18. 18

    How can I set wide screen when using R markdown with html output?

  19. 19

    How can I change PDF output font from within the YAML header when using Pandoc on Markdown?

  20. 20

    How can I make the application package available to the tests, when using py.test?

  21. 21

    How does FB messenger removes push notification from iOS app when I see the message on FB Desktop?

  22. 22

    How can I see which versions (platform/version/abi) of a package are available using pip3?

  23. 23

    Why can't I see any output when executing a windows batch file with VS code tasks

  24. 24

    When using BuildKit with Docker, how do I see the output of RUN commands?

  25. 25

    How do I see g++ compiler output when using Jam?

  26. 26

    When using Swift Package Manager how can I generate an Xcode project file for development

  27. 27

    How to call batch from powershell so I can see realtime output in powershell console

  28. 28

    UdpSocket.recv_from fails with "end of file" but I can see the incoming package in Wireshark

  29. 29

    UdpSocket.recv_from fails with "end of file" but I can see the incoming package in Wireshark

HotTag

Archive