nealrichardson / httptest

A Test Environment for HTTP Requests in R
https://enpiar.com/r/httptest/
Other
79 stars 10 forks source link

Tests using with_mock_api() fail with devtools::test() but not with devtools::check() #23

Closed ramiromagno closed 5 years ago

ramiromagno commented 5 years ago

hi

I do not know why but all my tests using with_mock_api() fail when I run devtools::test().

If I run devtools::check() instead all tests run fine.

Could this be an issue with httptest or with devtools?

devtools::check()

> devtools::check()
Updating gwasrapidd documentation
Writing NAMESPACE
Loading gwasrapidd
Writing NAMESPACE
── Building ──────────────────────────────────────────────────────────────────────────────────────── gwasrapidd ──
Setting env vars:
● CFLAGS    : -Wall -pedantic -fdiagnostics-color=always
● CXXFLAGS  : -Wall -pedantic -fdiagnostics-color=always
● CXX11FLAGS: -Wall -pedantic -fdiagnostics-color=always
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✔  checking for file ‘/home/rmagno/sci/code/R/pkg/gwasrapidd/DESCRIPTION’ ...
─  preparing ‘gwasrapidd’:
✔  checking DESCRIPTION meta-information ...
─  installing the package to build vignettes
✔  creating vignettes (1m 3.4s)
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  looking to see if a ‘data/datalist’ file should be added
─  building ‘gwasrapidd_0.99.1.tar.gz’

── Checking ──────────────────────────────────────────────────────────────────────────────────────── gwasrapidd ──
Setting env vars:
● _R_CHECK_CRAN_INCOMING_USE_ASPELL_: TRUE
● _R_CHECK_CRAN_INCOMING_REMOTE_    : FALSE
● _R_CHECK_CRAN_INCOMING_           : FALSE
● _R_CHECK_FORCE_SUGGESTS_          : FALSE
── R CMD check ───────────────────────────────────────────────────────────────────────────────────────────────────
─  using log directory ‘/tmp/Rtmpxl8X77/gwasrapidd.Rcheck’
─  using R version 3.6.0 (2019-04-26)
─  using platform: x86_64-pc-linux-gnu (64-bit)
─  using session charset: UTF-8
─  using options ‘--no-manual --as-cran’ (3s)
✔  checking for file ‘gwasrapidd/DESCRIPTION’
─  checking extension type ... Package
─  this is package ‘gwasrapidd’ version ‘0.99.1’
─  package encoding: UTF-8
✔  checking package namespace information ...
✔  checking package dependencies (1.6s)
✔  checking if this is a source package ...
✔  checking if there is a namespace
✔  checking for executable files (8.4s)
✔  checking for hidden files and directories ...
✔  checking for portable file names ...
✔  checking for sufficient/correct file permissions ...
✔  checking whether package ‘gwasrapidd’ can be installed (3s)
✔  checking installed package size ...
✔  checking package directory ...
✔  checking for future file timestamps (402ms)
✔  checking ‘build’ directory
✔  checking DESCRIPTION meta-information ...
✔  checking top-level files
✔  checking for left-over files ... 
✔  checking index information ...
✔  checking package subdirectories ...
✔  checking R files for non-ASCII characters ...
✔  checking R files for syntax errors ...
✔  checking whether the package can be loaded (365ms)
✔  checking whether the package can be loaded with stated dependencies ...
✔  checking whether the package can be unloaded cleanly ...
✔  checking whether the namespace can be loaded with stated dependencies ...
✔  checking whether the namespace can be unloaded cleanly ...
✔  checking loading without being on the library search path (353ms)
✔  checking dependencies in R code (546ms)
✔  checking S3 generic/method consistency (758ms)
✔  checking replacement functions ...
✔  checking foreign function calls (432ms)
✔  checking R code for possible problems (4s)
✔  checking Rd files (362ms)
✔  checking Rd metadata ...
✔  checking Rd line widths ...
✔  checking Rd cross-references ...
✔  checking for missing documentation entries (339ms)
✔  checking for code/documentation mismatches (1.1s)
✔  checking Rd \usage sections (1.1s)
✔  checking Rd contents ...
✔  checking for unstated dependencies in examples ...
✔  checking contents of ‘data’ directory ...
✔  checking data for non-ASCII characters (373ms)
✔  checking data for ASCII and uncompressed saves ...
✔  checking R/sysdata.rda ...
✔  checking installed files from ‘inst/doc’ ...
✔  checking files in ‘vignettes’ ...
✔  checking examples (15.1s)
   Examples with CPU or elapsed time > 5s
                 user system elapsed
   get_variants 1.644  0.052   6.887
✔  checking for unstated dependencies in ‘tests’ ...
─  checking tests ...
✔  Running ‘spelling.R’
✔  Running ‘testthat.R’ [17s/20s] (20.3s)
✔  checking for unstated dependencies in vignettes (20.5s)
✔  checking package vignettes in ‘inst/doc’ ...
✔  checking re-building of vignette outputs (55.1s)

── R CMD check results ──────────────────────────────────────────────────────────────────── gwasrapidd 0.99.1 ────
Duration: 2m 2.3s

0 errors ✔ | 0 warnings ✔ | 0 notes ✔

devtools::test(filter = 'get_metadata')

> devtools::test(filter = 'get_metadata')
Loading gwasrapidd
Testing gwasrapidd
✔ |  OK F W S | Context
✖ |  24 1     | test-metadata [0.5 s]
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────
test-get_metadata.R:175: error: get_metadata
GET https://www.ebi.ac.uk/gwas/rest/api/metadata (www.ebi.ac.uk/gwas/rest/api/metadata.json)
1: expect_identical(get_metadata(), lst0) at /home/rmagno/sci/code/R/pkg/gwasrapidd/tests/testthat/test-get_metadata.R:175
2: quasi_label(enquo(object), label, arg = "object")
3: eval_bare(get_expr(quo), get_env(quo))
4: get_metadata()
5: gc_request("/metadata", verbose = verbose, warnings = warnings) at /home/rmagno/sci/code/R/pkg/gwasrapidd/R/get_metadata.R:86
6: httr::GET(url, user_agent_id) at /home/rmagno/sci/code/R/pkg/gwasrapidd/R/request.R:39
7: request_perform(req, hu$handle$handle)
8: request_fetch(req$output, req$url, handle)
9: (function (req, handle, refresh) 
   {
       req$url <- sub("^:///", "", req$url)
       f <- buildMockURL(get_current_requester()(req))
       mockfile <- find_mock_file(f)
       if (!is.null(mockfile)) {
           return(load_response(mockfile, req))
       }
       req$mockfile <- f
       return(stop_request(req))
   })(req)
10: stop_request(req)
11: stop(out, call. = FALSE)
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────

══ Results ═══════════════════════════════════════════════════════════════════════════════════════════════════════
Duration: 0.5 s

OK:       24
Failed:   1
Warnings: 0
Skipped:  0
ramiromagno commented 5 years ago

Session Info

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS:   /usr/lib/libopenblasp-r0.3.6.so
LAPACK: /usr/lib/liblapack.so.3.8.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_DK.utf8         LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] httptest_3.2.2    gwasrapidd_0.99.1 testthat_2.1.1   

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1        plyr_1.8.4        pillar_1.4.0      compiler_3.6.0    prettyunits_1.0.2 remotes_2.0.4    
 [7] tools_3.6.0       digest_0.6.18     packrat_0.5.0     pkgbuild_1.0.3    pkgload_1.0.2     lubridate_1.7.4  
[13] jsonlite_1.6      concatenate_1.0.0 memoise_1.1.0     tibble_2.1.1      pkgconfig_2.0.2   rlang_0.3.4      
[19] cli_1.1.0         rstudioapi_0.10   curl_3.3          stringr_1.4.0     withr_2.1.2       dplyr_0.8.1      
[25] httr_1.4.0        desc_1.2.0        fs_1.3.1          devtools_2.0.2    triebeard_0.3.0   rprojroot_1.3-2  
[31] tidyselect_0.2.5  glue_1.3.1        R6_2.4.0          processx_3.3.1    sessioninfo_1.1.1 tidyr_0.8.3      
[37] pingr_1.1.2       callr_3.2.0       purrr_0.3.2       magrittr_1.5      backports_1.1.4   urltools_1.7.3   
[43] ps_1.3.0          usethis_1.5.0     assertthat_0.2.1  stringi_1.4.3     crayon_1.3.4 
ramiromagno commented 5 years ago

I just installed httptest github's version and now this problem is gone.

Apparently I had this problem before too. But with my recent update to R 3.6.0, I forgot I had installed CRAN's version httptest again.