Testthat does not work in devtools :: check, but works in devtools :: test

Is there any way to reproduce the medium that is used devtools::check?

I have a problem with what my tests work with devtools::test(), but crashes in devtools::check(). My problem is how to find the problem. The report checksimply prints the last few lines of the error log, and I cannot find the full report for testing.

checking tests ... ERROR
Running the tests in ‘tests/testthat.R’ failed.
Last 13 lines of output:
...

I know that I am checkusing a different environment compared to test, but I do not know how to debug these problems, since they do not reproduce at all. Especially these tests, where it works several months ago, so they are not sure where to look for the problem.

EDIT

Actually, I tried to find my problem, and found a solution. But in order to publish my solution, I have to add more information.

Thus, my test always failed, since I tested the markdown script if it worked without errors, and then I checked if some of the environment variables were set correctly. This is where the results that I calculate with the script, as well as the standard settings that I set. So I wanted to get a warning if I forgot to change some of my settings after development ...

In any case, since this is a markdown script, I had to extract the code, and I used the comments from this knitr post: run all the pieces in the Rmarkdown document using knitr::purlto get the code and sys.sourceto execute it.

runAllChunks <- function(rmd, envir=globalenv()){
  # as found here /questions/354953/knitr-run-all-chunks-in-an-rmarkdown-document
  tempR <- tempfile(tmpdir = '.', fileext = ".R")
  on.exit(unlink(tempR))
  knitr::purl(rmd, output=tempR, quiet=TRUE)
  sys.source(tempR, envir=envir)
}

- , ( , ...). , knitr::knit, , , , .

, , , , .

+6
4

testthat. , tests/testthat.R:

Sys.setenv(R_TESTS="")
+1

, devtools::test() devtools::test() ( devtools::test() devtools::check()). , , .

, , Suggests, Imports/Depends. , httr::content(), , as = "parsed". , as = "parsed" readr csv, , devtools::check() .

+1

So, as I mentioned above, I changed part of my code to user knitr::purl, but did not use it knitr::knit, and this solved my problem.

expect_error(f <- runAllChunks('010_main_lfq_analysis.Rmd'), NA)
expect_error(f <- knitr::knit('010_main_lfq_analysis.Rmd', output='jnk.R', quiet=TRUE, envir=globalenv()), NA)
0
source

If it helps someone else, this is what helped me.

  1. Reinstall all related packages. For example, install.packages("testthat", "dplyr", "lubridate", "stringr")(I have included all the packages that my package uses)
  2. Close RStudio and reopen

Then all the tests are passed

0
source

Source: https://habr.com/ru/post/1686088/


All Articles