Hi testthat team,
It seems like assigning does not work inside expect_condition() but does work inside expect_message() and expect_warning():
library(testthat)
foo_message <- function() {
message("a message")
5
}
expect_message(a <- foo_message())
a
#> [1] 5
expect_condition(b <- foo_message())
b
#> Error in eval(expr, envir, enclos): object 'b' not found
foo_warning <- function() {
warning("a warning")
5
}
expect_warning(c <- foo_warning())
c
#> [1] 5
expect_condition(d <- foo_warning())
d
#> Error in eval(expr, envir, enclos): object 'd' not found
Created on 2020-03-26 by the reprex package (v0.3.0)
I don’t know, if this difference is intended. However, I find it sometimes useful to do stuff like this, which is inspired by the examples of expect_message:
expect_warning(c <- foo_warning())
expect_equal(c, 5)
Created on 2020-03-26 by the reprex package (v0.3.0)
Hi testthat team,
It seems like assigning does not work inside
expect_condition()but does work insideexpect_message()andexpect_warning():Created on 2020-03-26 by the reprex package (v0.3.0)
I don’t know, if this difference is intended. However, I find it sometimes useful to do stuff like this, which is inspired by the examples of
expect_message:Created on 2020-03-26 by the reprex package (v0.3.0)