Skip to content

snapshot test fails and requests edition3 when it is in package setup, fails as well if local_edition() is switched to edition3 #1935

@PierreENOlivier

Description

@PierreENOlivier

Hello,
I have some snapshot tests failing in our company package.
We use expect_snapshot() which requires edition3.

Edition3 is configured in the DESCRIPTION of the package and via usethis::use_testthat(edition = 3).
I, thus, assume that the default edition in the package should be edition3. This version can be overridden locally using testthat::local_edition(2) which should only apply inside the test where it is called.

N.B. The following dummy tests are in the same file.

test_that('Generate binary matrix', {
  data <- 
    tibble(
      var1 = c(1, 0, 1, 0, 1),
      var2 = c(0, 0, 0, 1, 1),
      var3 = c(1, 0, 1, 1, 1)
    )

    # testthat::local_edition(3) # will fix the first test
    expect_snapshot(data)

})

test_that('Generate character matrix', {
  data_let <- 
    tibble(
      var1 = letters[1:5],
      var2 = letters[6:10],
      var3 = letters[11:15]
    )

    expect_snapshot(data_let)

})

Observations:

  1. If I click the "Run Tests" button on the file, it will generate the snapshot the first time and any following runs will succeed without errors.
  2. If I run all tests (Build > Test), then the same tests that previously succeeded will fail asking for local_edition(3) testthat:::edition_require(3, "expect_snapshot()").
  3. If I add the local_edition(3), the tests will fail saying that the snapshot has changed (though it should be the same). The only character that seems to have changed is the 'x' sign in 'A tibble: 5 x 3'. The old snapshot has a bold 'x' and the new snapshot has a normal font 'x'.

Is it a bug or something wrong with my config?

Thanks in advance,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions