I am trying to setup testthat so that ignores all lifecycle-related deprecation warnings. To do so I am setting option(lifecycle.verbosity = "quiet") in "tests/testthat/setup.R". The option seems to be carried over to the actual test-environment, but the code within the tests still throws deprecation warnings although option(lifecycle.verbosity = "quiet") is set.
tests/testthat/setup.R:
op <- options(lifecycle.verbosity = "quiet")
withr::defer(options(op), testthat::teardown_env())
tests/testthat/test-hello.R
test_that("does dplyr warn or not?", {
expect_equal(getOption("lifecycle.verbosity"), "quiet")
expect_no_warning(
dplyr::tibble(x = 1) |>
dplyr::mutate(
y = dplyr::case_match(x, 1 ~ 2)
)
)
})
devtools::test()
# ℹ Testing test
# ✔ | F W S OK | Context
# ✖ | 1 1 | hello
# ────────────────────────────────────────────────────────────────────────────────────────────────────────
# Failure (test-hello.R:6:3): does dplyr warn or not?
# Expected `dplyr::mutate(...)` not to throw any warnings.
# Actually got a <rlang_warning> with message:
# There was 1 warning in `dplyr::mutate()`.
# i In argument: `y = dplyr::case_match(x, 1 ~ 2)`.
# Caused by warning:
# ! `case_match()` was deprecated in dplyr 1.2.0.
# i Please use `recode_values()` instead.
# ────────────────────────────────────────────────────────────────────────────────────────────────────────
#
# ══ Results ═════════════════════════════════════════════════════════════════════════════════════════════
# ── Failed tests ────────────────────────────────────────────────────────────────────────────────────────
# Failure (test-hello.R:6:3): does dplyr warn or not?
# Expected `dplyr::mutate(...)` not to throw any warnings.
# Actually got a <rlang_warning> with message:
# There was 1 warning in `dplyr::mutate()`.
# i In argument: `y = dplyr::case_match(x, 1 ~ 2)`.
# Caused by warning:
# ! `case_match()` was deprecated in dplyr 1.2.0.
# i Please use `recode_values()` instead.
#
# [ FAIL 1 | WARN 0 | SKIP 0 | PASS 1 ]
I couldn't figure out how to make a reprex that emulates a test-run, so I am attaching a minimal package filestructure that shows the problem when calling devtools::test() within: test_package.zip
I am trying to setup testthat so that ignores all lifecycle-related deprecation warnings. To do so I am setting
option(lifecycle.verbosity = "quiet")in "tests/testthat/setup.R". The option seems to be carried over to the actual test-environment, but the code within the tests still throws deprecation warnings althoughoption(lifecycle.verbosity = "quiet")is set.tests/testthat/setup.R:
tests/testthat/test-hello.R
I couldn't figure out how to make a reprex that emulates a test-run, so I am attaching a minimal package filestructure that shows the problem when calling
devtools::test()within: test_package.zip