Skip to content

Commit

Permalink
Default to no progress bar in tests (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored Sep 5, 2024
1 parent 6f78779 commit fa27e9e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# httr2 (development version)

* `req_perform()` no longer displays a progress bar when sleeping during tests. You can override this behaviour by setting the option `httr2_progress`.
* `req_cache()` now re-caches the response if the body is hasn't been modified but the headers have changed (#442).
* `req_cache()` works better when `req_perform()` sets a path (#442).
* `req_body_*()` now give informative error if you attempt to change the body type (#451).
Expand Down
9 changes: 5 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ modify_list <- function(.x, ..., error_call = caller_env()) {
}


sys_sleep <- function(seconds,
task,
fps = 10,
progress = getOption("httr2_progress", TRUE)) {
sys_sleep <- function(seconds, task, fps = 10, progress = NULL) {
check_number_decimal(seconds)
check_string(task)
check_number_decimal(fps)
progress <- progress %||% getOption("httr2_progress", !is_testing())
check_bool(progress, allow_null = TRUE)

if (seconds == 0) {
return(invisible())
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
Error:
! All components of `...` must be named.

# can suppress progress bar
# progress bar suppressed in tests

Code
sys_sleep(0.1, "for test")
sys_sleep(0.1, "in test")
Message
> Waiting 1s for test
> Waiting 1s in test

6 changes: 2 additions & 4 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ test_that("respects httr verbose config", {
expect_equal(httr2_verbosity(), 1)
})

test_that("can suppress progress bar", {
withr::local_options(httr2_progress = FALSE)

expect_snapshot(sys_sleep(0.1, "for test"))
test_that("progress bar suppressed in tests", {
expect_snapshot(sys_sleep(0.1, "in test"))
})

0 comments on commit fa27e9e

Please sign in to comment.