mercredi 3 mars 2021

Check that a test_that block is failing and report seed

I want to cat() some information to the console in the case a test fails (I'm getting confident this won't happen but I can't prove it wont) so I can investigate the issue.

Now I have code that is approximately like this:

testthat::test_that('Maybe fails', {
  seed <- as.integer(Sys.time())
  set.seed(seed)
  
  testthat::expect_true(maybe_fails(runif(100L)))

  if (failed()) {
    cat('seed: ', seed, '\n')
  }
})

Unfortunately, failed() doesn't exist.

Return values of expect_*() don't seem useful, they just return the actual argument.

I'm considering to just check again using all.equal() but that is a pretty ugly duplication.

Aucun commentaire:

Enregistrer un commentaire