testthat
testthat copied to clipboard
JunitReporter fails badly on warning outside of test_that
Hi! I wanted to share an use case in which JunitReporter throws and others don't.
I had the following (pseudo-code)
new_foo <- \(...) {...}
old_foo <- \(...) {
lifecycle::deprecate_warn(...)
new_foo(...)
}
In test file:
x <- old_foo(...)
test_that("foo is working", {
...
})
When using JunitReporter
and only(!) during check it fails as follows:
Error in UseMethod("xml_add_child") :
no applicable method for 'xml_add_child' applied to an object of class "NULL"
Calls: test_check ... o_apply -> lapply -> FUN -> <Anonymous> -> <Anonymous>
Execution halted
This line in particular: https://github.com/r-lib/testthat/blob/07c5cd99c3098b9f228258fe7a3df5a3e9a7a2b8/R/reporter-junit.R#L106-L111
For some reason self$suite
is NULL
when calling $add_result()
method. My guess is it's because it's outside of test_that
.
We have addressed this internally by changing x <- old_foo()
into x <- new_foo()
but I think it would be good to share it with you as this was not a problem for a default reporter (haven't checked all of them) as well as within TEST (as opposed to CHECK).