You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I really enjoy using use_test() and use_r(), but was wondering whether there could be an equivalent for creating a tests/testthat/helper- file? (I didn't find any related issue but might have missed one 😅)
I made a little sketch. I don't really like that the default isn't consistent with the default of use_test(), but also I think that having a helper file for each test file by default seems a bit overkill.
I'm generally on board, so am happy to see this in PR form. I'm not sure the name and scope arguments are quite right yet. I don't have great vocabulary for stuff yet, but clearly we want to make it easy to ask for helper.R versus helper-stuff.R. I think 1 argument is enough. "Suffix" almost captures it, but it's not perfect 🤔
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):
Test helper files don't have the same tight coupling as R/whatever.R and tests/testthat/test-whatever.R. We think of a test helper file as belonging to the package not to a specific R or test file. Which is why the default is a plain old tests/testthat/helper.R.
So I definitely don't see the need to support the file creation/opening functionality that use_r()/use_test() provide for managing the pair of files.
In terms of what that means for use_test_helper(), that just leaves the initial creation of a helper file. Which might not really justify adding a new function 🤔
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 "tests/testthat/helper.R"). The only added feature could perhaps be a way to create "tests/testthat/helper-foo.R", if it's the kind of package with multiple helper files. Let's leave this one available for tidyverse dev day. Ah, I see there is already a PR in flight. Will comment on that, then.
Activity
olivroy commentedon Oct 20, 2023
I agree. I think it may be a little bit less straightfoward than the other 2 (
use_r()anduse_test())Should there be an option for a generic test helper
"tests/testthat/helper.R", vs file specific test helper?Also, important to note that
R/helper.Randtests/testthat/helper.Rmay not be related.olivroy commentedon Mar 19, 2024
I made a little sketch. I don't really like that the default isn't consistent with the default of
use_test(), but also I think that having a helper file for each test file by default seems a bit overkill.usethis/R/r.R
Lines 57 to 71 in fdb4a72
jennybc commentedon Mar 22, 2024
I'm generally on board, so am happy to see this in PR form. I'm not sure the
nameandscopearguments are quite right yet. I don't have great vocabulary forstuffyet, but clearly we want to make it easy to ask forhelper.Rversushelper-stuff.R. I think 1 argument is enough. "Suffix" almost captures it, but it's not perfect 🤔jennybc commentedon Jun 27, 2024
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):
R/whatever.Randtests/testthat/test-whatever.R. We think of a test helper file as belonging to the package not to a specific R or test file. Which is why the default is a plain oldtests/testthat/helper.R.use_r()/use_test()provide for managing the pair of files.use_test_helper(), that just leaves the initial creation of a helper file. Which might not really justify adding a new function 🤔olivroy commentedon Jun 27, 2024
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
edit_file("tests/testthat/helper.R")is a bit clumsy.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
load_all(), but they are not used that much in the wild.But otherwise, feel free to close and I will just add this to my .Rprofile/
Looking at it, it's true that it doesn't seem worth the effort. Maybe adding this example to the documentation of
edit_file()would be a good idea?jennybc commentedon Jul 22, 2024
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
"tests/testthat/helper.R"). The only added feature could perhaps be a way to create"tests/testthat/helper-foo.R", if it's the kind of package with multiple helper files.Let's leave this one available for tidyverse dev day.Ah, I see there is already a PR in flight. Will comment on that, then.