Learn R Programming

testthat (version 3.2.2)

with_mock: Mock functions in a package.

Description

[Deprecated]

with_mock() and local_mock() are deprecated in favour of with_mocked_bindings() and local_mocked_bindings().

These functions worked by using some C code to temporarily modify the mocked function in place. This was an abuse of R's internals and it is no longer permitted.

Usage

with_mock(..., .env = topenv())

local_mock(..., .env = topenv(), .local_envir = parent.frame())

Value

The result of the last unnamed parameter

Arguments

...

named parameters redefine mocked functions, unnamed parameters will be evaluated after mocking the functions

.env

the environment in which to patch the functions, defaults to the top-level environment. A character is interpreted as package name.

.local_envir

Environment in which to add exit handler. For expert use only.