Skip to content

Commit b8a4c47

Browse files
authored
Explicitly pass parent.frame() in it() (#2086)
Fixes #2085
1 parent 6dd8896 commit b8a4c47

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# testthat (development version)
22

3+
* `it()` now finds the correct evaluation environment in more cases (@averissimo, #2085).
34
* Fixed an issue preventing compilation from succeeding due to deprecation / removal of `std::uncaught_exception()` (@kevinushey, #2047).
45

56
# testthat 3.2.3

R/describe.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ it <- function(description, code = NULL) {
9494
check_string(description, allow_empty = FALSE)
9595

9696
code <- substitute(code)
97-
describe_it(description, code)
97+
describe_it(description, code, env = parent.frame())
9898
}

tests/testthat/test-describe.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ describe("describe", {
3737
expect_equal(1, someInternalVariable)
3838
})
3939

40+
# prefix is needed to test this use case
41+
testthat::it("should be possible to use variables from outer environments with package prefix", {
42+
expect_equal(1, someExternalVariable)
43+
expect_equal(1, someInternalVariable)
44+
})
45+
4046
it("should not be possible to access variables from other specs (1)", {
4147
some_test_var <- 5
4248
})

0 commit comments

Comments
 (0)