-
Notifications
You must be signed in to change notification settings - Fork 340
Closed
Description
I'm trying to test my Setup.R file by sourcing the file. However, in that context, teardown_env() is not properly initialized so I get an error.
Here is a simple example:
handle <- file(tempfile())
withr::defer(close(handle),testthat::teardown_env())
#> Error in `testthat::teardown_env()`:
#> ! `teardown_env()` has not been initialized
#> ℹ This is an internal error that was detected in the testthat package.
#> Please report it at <https://github.com/r-lib/testthat/issues> with a reprex (<https://tidyverse.org/help/>) and the full backtrace.Created on 2024-11-22 with reprex v2.1.1
Here is the backtrace:
Backtrace:
▆
1. ├─base::source("~/ralmond1/Projects/Peanut/tests/testthat/setup.R")
2. │ ├─base::withVisible(eval(ei, envir))
3. │ └─base::eval(ei, envir)
4. │ └─base::eval(ei, envir)
5. ├─withr::defer(...) at tests/testthat/setup.R:16:1
6. └─testthat::teardown_env()
I don't think this is a bug so much as a bit of missing functionality. It would be good to have a way to artificially call Setup.R and then emulate the teardown, so that I can validate that my Setup code is working.
Metadata
Metadata
Assignees
Labels
No labels