Skip to content
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

describe_it() should set the test_code() reporter like test_that() #1782

Closed
DavisVaughan opened this issue May 4, 2023 · 1 comment · Fixed by #1808
Closed

describe_it() should set the test_code() reporter like test_that() #1782

DavisVaughan opened this issue May 4, 2023 · 1 comment · Fixed by #1808
Milestone

Comments

@DavisVaughan
Copy link
Member

DavisVaughan commented May 4, 2023

describe_it <- function(description, code, env = parent.frame()) {

In bench there is this test, which I can't run interactively:

describe("bench_time", {
  skip_on_cran()
  skip_on_ci()

  res <- bench_time(1 + 1:1e7)
  it("returns process and real time", {
    expect_equal(names(res), c("process", "real"))
  })
  # snip...
})

The problem is that local_interactive_reporter() isn't set up, which is what sets NOT_CRAN=true, so the test fails in skip_on_cran() because it "looks like we are on cran"

test_that() does this nice thing where if it detects that there is no reporter active, it sets up an interactive reporter for you, and I think describe_it() (used by both describe() and it()) should do the same thing

testthat/R/test-that.R

Lines 41 to 44 in 4076b66

reporter <- get_reporter()
if (is.null(reporter)) {
reporter <- local_interactive_reporter()
}

That should mean you can run both the full describe() block and just an it() block interactively and both should get NOT_CRAN=true set up correctly.


Hadley also mentioned during discussion about this:

also I was wondering if skip_on_cran() should check interactive() first

the main downside of the current behaviour is that you sometimes want to nest skip_on_cran() inside a helper, and then you can’t run that interactively

Update: This part is solved by #1789

@hadley hadley added this to the 3.1.8 milestone Jun 2, 2023
@hadley
Copy link
Member

hadley commented Jun 4, 2023

Note to self: look in git stash

hadley added a commit that referenced this issue Jun 4, 2023
hadley added a commit that referenced this issue Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants