some_func <- function() stop("oops")
some_other_func <- function() some_func()
my_env <- environment()
tester_func <- function() {
# The default for .env works well most of the time,
# unfortunately not in examples
local_mock(some_func = function() 42, .env = my_env)
some_other_func()
}
try(some_other_func())
tester_func()
tester_func_with <- function() {
with_mock(
some_func = function() 42,
.env = my_env,
{
some_other_func()
}
)
}
tester_func_with()
Run the code above in your browser using DataLab