r-lib / progress

Progress bar in your R terminal
http://r-lib.github.io/progress/
Other
468 stars 39 forks source link

testthats of new packages fail with R CMD CHECK #110

Closed mkirzon closed 4 years ago

mkirzon commented 4 years ago

Summary

progress_bar messages used within external packages have weird behavior when testthat unit tests are attempted by R CMD CHECK. I suspect environments are at play.

More details

I made a package that leverages "progress". In my package, I have a function that uses progress_bar, which looks something like:

myFunction = function() { 

  # some code

  mode = "date"
  progress_bar$new(
    total = length(someVector), 
    format = sprintf("[:bar] :current/:total %s batches (eta :eta)", mode), 
    clear = TRUE, show_after = 0)

  # more code 
}

Then to test my package, I use "testthat" and search for my custom progress messages using:

expect_message(myFunction(), regex("date batches"))

For some mysterious reason, these tests pass when run interactively with devtools::test() but fail when executed by R CMD CHECK. The test output claims that my function "did not produce any messages" even though when run interactively, this works fine.

I think this may be a convoluted issue so not sure how to create a reprex.

gaborcsardi commented 4 years ago

progress turns off the progress bar by default in non-interactive sessions. See the force argument and progress's own tests, e.g. https://github.com/r-lib/progress/blob/b146a6a74d14c1cf4a3689ae745a0c0f38a355d2/tests/testthat/test-progress.R#L6

mkirzon commented 4 years ago

Thank you so much... I can't believe I didn't realize that.