testthat icon indicating copy to clipboard operation
testthat copied to clipboard

`expect_no_error()` reports both PASS and FAIL (when it actually should only FAIL)

Open dheimgartner opened this issue 1 year ago • 1 comments

The following test

test_that("should intentionally fail", {
  erroneous_function <- function() {
    stop("I am an errouneous function!")
  }
  expect_no_error(erroneous_function())
})

produces the following output

> devtools::test()
ℹ Testing testingBug
✔ | F W  S  OK | Context
✖ | 1        1 | example                                                                                                                       
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Failure (test-example.R:3:5): should intentionally fail
Expected `erroneous_function()` to run without any errors.
i Actually got a <simpleError> with text:
  I am an errouneous function!
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

══ Results ════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
── Failed tests ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Failure (test-example.R:3:5): should intentionally fail
Expected `erroneous_function()` to run without any errors.
i Actually got a <simpleError> with text:
  I am an errouneous function!

[ FAIL 1 | WARN 0 | SKIP 0 | PASS 1 ]

Why does it report OK 1 and PASS 1 when the only test actually fails (it produces an error)?

dheimgartner avatar Oct 19 '24 15:10 dheimgartner

Hmmm, weird. Even simpler reprex:

test_that("should intentionally fail", {
  expect_no_error(foo())
})

hadley avatar Oct 22 '24 17:10 hadley