There does not currently seem to be a good way to override config parameters for testing.
Assume you have e.g. a Shiny app which records uploads in a storage folder. In production, this is set to some appropriate location via config::get("storage_path"). During unit testing, this value should point to a temporary folder removed after the end of a test_that call. Creating a temporary config.yml in pkg_root/tests/testthat does not seem to be a good idea for various reasons, including potentially parallel test execution. Changing the CWD is not really supported by test_that, as test_path(x) will return x while executing tests and tests/testthat while not executing tests.
It would be good to have some sort of withr style way to override individual variables for the duration of a test, simply to force output into a temporary directory.
For what it's worth, test_that should IMO run tests in tests/testthat in a temporary directory, but that's a different issue. It would still be good to be able to override config::get values within a scope.
There does not currently seem to be a good way to override config parameters for testing.
Assume you have e.g. a Shiny app which records uploads in a storage folder. In production, this is set to some appropriate location via
config::get("storage_path"). During unit testing, this value should point to a temporary folder removed after the end of atest_thatcall. Creating a temporaryconfig.ymlinpkg_root/tests/testthatdoes not seem to be a good idea for various reasons, including potentially parallel test execution. Changing the CWD is not really supported by test_that, astest_path(x)will returnxwhile executing tests andtests/testthatwhile not executing tests.It would be good to have some sort of withr style way to override individual variables for the duration of a test, simply to force output into a temporary directory.
For what it's worth,
test_thatshould IMO run tests intests/testthatin a temporary directory, but that's a different issue. It would still be good to be able to override config::get values within a scope.