-
Notifications
You must be signed in to change notification settings - Fork 321
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
Docs around R/test-helpers.R vs tests/testthat/setup.R #1206
Comments
I see testthat/vignettes/test-fixtures.Rmd Line 264 in fbbd667
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Because we're moving away from It's not a special file — you can put it in any file in |
But there are still things you'd put in setup.R, right?
|
Right I see https://testthat.r-lib.org/articles/test-fixtures.html#package It is now clearer to me, thanks. I wonder whether a summary of where to put helper code (based on when it should be run and available) might be useful somewhere, but if not then this issue is useless. 🙂 |
From the community thread, it seems one "point" that helper files in |
Why do you want test and code to be distinct? They have to be intertwined. |
Maybe the docs could state that since that's a difference between the previous recommendation of tests/testthat/helper- and the current recommendation? (I have to say I have no opinion on this) |
If your helper code is in R you can no longer skip its loading using the corresponding argument of |
A couple of possible reasons:
For the packages I have encountered, setup/helper code is small, and the other issues are not very hard to work around, so I am not saying that they are strong reasons. |
I've just thought of another reason, not important at all: to globally analyze what people put in their testthat helpers (à la https://rud.is/b/2018/04/08/dissecting-r-package-utility-belts/), it's easier if such helpers live in |
To be clear, helper files aren't going away, they're just no longer recommended. @gaborcsardi if you have a lot of setup/helper code I'd argue that it's even more important that it live in |
@hadley do you actually know of any package testing setup/helper code? |
Nope 😄 |
I've just thought of an advantage of defining helpers under R/: if you use two test directories (see point 19 in https://cran.r-project.org/doc/manuals/R-exts.html#Checking-packages), then both of them have access to the helpers. |
I think the conclusion to this thread is that I don't need to do anything; please let me know if you think otherwise. |
This became inspiration for a blog post with a summary table https://blog.r-hub.io/2020/11/18/testthat-utility-belt/ |
Also locating them in R/ makes usage of the R language server more enjoyable! |
In https://testthat.r-lib.org/articles/custom-expectation.html it is written "Since these functions will need to be loaded when your package is loaded for testing, it is recommended that expect_ functions be defined in test-helpers.R in your packages R/ directory"
why not in setup.R?
depending on the answer to the previous question, should the recommendation to use the filename "test-helpers.R" be added to https://testthat.r-lib.org/reference/test_dir.html#special-files:?
The text was updated successfully, but these errors were encountered: