r-lib / testthat

An R 📦 to make testing 😀
https://testthat.r-lib.org
Other
888 stars 317 forks source link

Change the structure of package autotesting: from "tests/testthat/*" to "tests/*" #1644

Closed avraam-inside closed 2 years ago

avraam-inside commented 2 years ago

Hi!

I actively use the autotesting functionality, there are already hundreds of tests and dozens of test files in the package, and for many months of work I have felt the MAXIMUM discomfort from an extra click on tests/testthat/*.

As a user, this extra nesting seems a bit superfluous to me.

There is some magic combination of settings via options/.Rprofile/etc which will allow me to place test files immediately in the tests/ folder, without testthat/-folder?

hadley commented 2 years ago

No, it's not possible with the way that testthat is designed, sorry.

avraam-inside commented 2 years ago

No, it's not possible with the way that testthat is designed, sorry.

Why is it impossible? It is only expected to delete the extra folder level. This extra click on the folder is not particularly useful.

hadley commented 2 years ago

Because of the way that R CMD check runs tests.

I don't ever manually click on the tests/ folder, so you might want (re) read https://r-pkgs.org/tests.html and consider your testing workflow.

avraam-inside commented 2 years ago

Sorry, I forgot about our conversation...

In general, I did the "impossible":

test <- function() {
    testthat::test_dir(here::here('tests'))
    return(invisible(NULL))
}

testFile <- function() {
    testthat::test_file(rstudioapi::getSourceEditorContext()$path)
    return(invisible(NULL))
}

And I read the documentation well, but it's IMPOSSIBLE not to go directly into the file, I have a lot of fine work with environments, folders, etc. that needs to be debugged directly in tests. In python, I also go directly to the test files with colleagues when we test the backend of the Process Mining web service.

But in a good way, take and drag these functions directly into testthat, so that it is not my local setting.