-
Notifications
You must be signed in to change notification settings - Fork 318
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
Feature request: Run a single named test within a file #1776
Comments
This would also be useful for front-ends which might want to provide UI for running individual tests (either interactively or potentially separately in a new R process) |
What should happen to other non-test code in the file. Should it get run? What happens if there are multiple tests that happen to have the same name? |
I think so. The way I imagine it, the whole file is run in the "regular" way, but
I guess this could be made an error? |
Some maybe something like this (untested): library(rlang)
run_one_test <- function(path, name, env = parent.frame()) {
exprs <- parse(path, keep.source = TRUE)
run <- FALSE
for (expr in exprs) {
if (is_call(expr, "test_that", n = 2)) {
if (!is_string(test_that[[2]]))
next
test_name <- as.character(test_that[[2]])
if (test_name != name)
next
if (run) {
cli::cli_abort("Multiple tests with specified name")
}
run <- TRUE
}
eval(expr, envir = env)
}
if (!run) {
cli::cli_abort("Failed to find test with name")
}
invisible()
} |
I think it'd be simpler to have It also ensures that 'single' tests get run in the same way as a whole file, respecting all of the other setup that |
Yeah, sorry I wasn't suggesting this as the real implementation, just something that concretely expressed the logic so we could be sure we were both saying the same thing. |
Currently, the smallest unit of tests that can be run with this package is a file, with
testthat::test_file()
. However, for our use case each testing file (we've already split up into about 10 of them) takes 5-10 minutes to run, so the dev loop for tests at the end of a file is painfully slow. Therefore I propose something liketestthat::test_single(file, test_name)
to run a single named test within a file, skipping over all tests whose names do not match test_name.The text was updated successfully, but these errors were encountered: