-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
FR: use_test_helper() #1822
Comments
I agree. I think it may be a little bit less straightfoward than the other 2 ( Should there be an option for a generic test helper Also, important to note that |
I made a little sketch. I don't really like that the default isn't consistent with the default of Lines 57 to 71 in fdb4a72
#' @rdname use_r
#' @export
#' @param scope if global, creates "tests/testthat/helper.R", otherwise creates
#' "tests/testthat/helper-{name}.R
use_test_helper <- function(name = NULL, scope = c("global", "file"), open = rlang::is_interactive()) {
if (!uses_testthat()) {
use_testthat_impl()
}
scope <- arg_match(scope)
if (scope == "global") {
path <- path("tests", "testthat", "helper", ext = "R")
} else {
path <- path("tests", "testthat", paste0("helper-", compute_name(name)))
}
edit_file(proj_path(path), open = open)
ui_bullets(c(
"_" = "Run {.run devtools::load_all()} to load objects from helper files in
your environment."
)
)
invisible(TRUE)
} |
I'm generally on board, so am happy to see this in PR form. I'm not sure the |
Starting to actually think about this now, including the PRs #1978 and #1990. Some high-level thoughts (informed by a quick consult with @hadley too):
|
it would also be useful to access it to add new functions to it. I would understand that it may not be worth a new function, but typing In terms of promoting good workflow, it would be a + too., I find test helpers are life savers for efficient testing workflows (as they are loaded with But otherwise, feel free to close and I will just add this to my .Rprofile/ use_test_helper <- function() usethis::edit_file("tests/testthat/helper.R") Looking at it, it's true that it doesn't seem worth the effort. Maybe adding this example to the documentation of |
I'd be happy to review a small PR with a small function that helps to create (and open) a test helper file, in the right place, with a good name (defaulting to |
I really enjoy using
use_test()
anduse_r()
, but was wondering whether there could be an equivalent for creating atests/testthat/helper-
file? (I didn't find any related issue but might have missed one 😅)The text was updated successfully, but these errors were encountered: