-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.setup= argument to allow re-usable (but hermetic) local variables? #13
Comments
My examples tend to focus on local variables that aren't expensive to compute. Your example is a bit like that too, and it shouldn't be a problem to run that code every time. Each patrick iteration should be in a clean environment. I'd rewrite your lintr example like this, which is more in line with the docs:
But I can see some value here for cases where some of the values needed in the parameterized test are expensive to compute. When using parameterized tests, setUp is called every time. This is for a clean environment, like you said. You I'll see what I can do here. |
In plain {testthat} we can re-use local variables "hermetically" by running some code before expectations:
After
"a test"
runs, we don't have to worry about other tests "seeing"var1
/var2
, their scope is restricted.It's not so easy to do this with {patrick}, because we want to declare just once variables used across all the
.cases
. We might also want to declare the.cases
themselves.The workaround that I've landed on is to wrap
with_parameters_test_that()
withlocal({})
, but this is a tad clumsy and usage oflocal({})
is not so prevalent in R code, so it slightly harms readability IMO.One solution would be to offer a
.setup
argument that encapsulates whatlocal()
is doing:.setup
is run first, sovar1
andvar2
are available tocode
but also to the other arguments in thewith_parameters_test_that
call.WDYT?
The text was updated successfully, but these errors were encountered: