Skip to content

Play nice with testthat #45

Description

@epruesse

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions