These functions represent a second attempt at bringing mocking to testthat, incorporating what we've learned from the mockr, mockery, and mockthat package.
with_mocked_bindings()
and local_mocked_bindings()
work by temporarily
changing variable bindings in the namespace of namespace .package
.
Generally, it's only safe to mock packages that you own. If you mock other
packages, we recommend using skip_on_cran()
to avoid CRAN failures if the
implementation changes.
These functions do not currently affect registered S3 methods.
local_mocked_bindings(..., .package = NULL, .env = caller_env())with_mocked_bindings(code, ..., .package = NULL)
Name-value pairs providing functions to mock.
The name of the package where mocked functions should be
inserted. Generally, you should not need to supply this as it will be
automatically detected when whole package tests are run or when there's
one package under active development (i.e. loaded with
pkgload::load_all()
).
Environment that defines effect scope. For expert use only.
Code to execute with specified bindings.