Closed scottkosty closed 7 years ago
What is your end goal here? I don't think it makes sense to use the built-in warning function, for the same reason that testthat automatically captures stop()
.
Do you just want the tests to fail overall if there are warnings present?
Thanks for the response.
I don't think it makes sense to use the built-in warning function, for the same reason that testthat automatically captures stop().
I see, that makes sense. But what about the second idea I mentioned above, of using the built-in warning at the end if any warnings were captured during any of the tests. Something like
warn("A warning occurred during a test")
Alternatively, whether a test is defined to "pass" or "fail" could depend on the "warn" option. If the "warn" option is 2, then if there is a warning the test "fails".
Do you just want the tests to fail overall if there are warnings present?
Yes, and I would prefer to be able to control that behavior by setting the 'warn' option.
Ok, that makes sense. I'll need to think through if we can just make this work with warn
or it would make sense to have another option (but I'm pretty sure we can just make use of warn)
First of all, thank you to everyone working on this package! I find it very useful.
I prefer to turn warnings into errors. (related discussion: http://r.789695.n4.nabble.com/Turn-warnings-or-notes-into-errors-on-CMD-check-td4698214.html)
However, testthat does not use R's warning mechanism for the warnings it prints. I think it would be better to rely on R's centralized warning mechanism than catting the string "warning".
More details:
R CMD check currently gives me:
As you can see, there is no warning in the output here. However, testthat does give warnings (see the output at the bottom for the specific warnings given).
If I inspect the created testthat.Rout file, I could see the warnings. But I do not want to manually set up a grep.
testthat could either use the
warning()
function for each warning. Or it could use cat but at least at the end use thewarning()
function once, such aswarning("there were warnings")
.If testthat does not want to use R's warnings for some reason, perhaps it could just use a different word (to me, a "warning" is well-defined in R), or perhaps respect conventions such as the "warn" option. For example, the warn option is ignored in the following: