Skip to content

describe_it doesn't find the right environment when it() is prefixed with testthat:: #2085

Open
@averissimo

Description

@averissimo

I believe the it function should pass the parent.frame() explicitly

See reproducible example below of failure

testthat::describe("a test", {
  aa <- 1
  it("should pass", {
    testthat::expect_equal(aa, 1)
  })
})
#> Test passed 🌈


testthat::describe("a test", {
  aa <- 1
  testthat::it("should pass", {
    testthat::expect_equal(aa, 1)
  })
})
#> ── Error: should pass ──────────────────────────────────────────────────────────
#> Error in `eval(code, test_env)`: object 'aa' not found
#> Backtrace:
#>     ▆
#>  1. └─testthat::expect_equal(aa, 1)
#>  2.   └─testthat::quasi_label(enquo(object), label, arg = "object") at testthat/R/expect-equality.R:62:3
#>  3.     └─rlang::eval_bare(expr, quo_get_env(quo)) at testthat/R/quasi-label.R:45:3
#> Error:
#> ! Test failed

library(testthat)
describe("a test", {
  aa <- 1
  testthat::it("should pass", {
    testthat::expect_equal(aa, 1)
  })
})
#> ── Error: should pass ──────────────────────────────────────────────────────────
#> Error in `eval(code, test_env)`: object 'aa' not found
#> Backtrace:
#>     ▆
#>  1. └─testthat::expect_equal(aa, 1)
#>  2.   └─testthat::quasi_label(enquo(object), label, arg = "object") at testthat/R/expect-equality.R:62:3
#>  3.     └─rlang::eval_bare(expr, quo_get_env(quo)) at testthat/R/quasi-label.R:45:3
#> Error:
#> ! Test failed

Created on 2025-06-04 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions