This seems to work fine within a test_that expression. Can this cause any problems?
random_function <- function(in_dir) {
return(file.access(in_dir, 0))
}
testthat::test_that("Base function is mocked correctly", {
testthat::expect_true(random_function("random/directory/that/does/not/exist") == -1)
testthat::local_mocked_bindings(
file.access = function(in_dir, mode) {
return(0)
}, .package = "base")
testthat::expect_true(random_function("random/directory/that/does/not/exist") == 0)
})
testthat::test_that("Base function is not mocked anymore", {
testthat::expect_true(random_function("random/directory/that/does/not/exist") == -1)
})