Skip to content

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

Closed

Description

@dheimgartner

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)?

Activity

  1. hadley commented on Oct 22, 2024

    @hadley
    Member

    Hmmm, weird. Even simpler reprex:

    test_that("should intentionally fail", {
      expect_no_error(foo())
    })
  2. added
    bug
    on Oct 22, 2024
  3. added a commit that references this issue on Nov 4, 2024
    fcabd5e
  4. added a commit that references this issue on Nov 5, 2024
    3f70084
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugconditions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions