Skip to content

lutzgruber-quantco/demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

Lutz Gruber 2021-07-15

This is package serves to demonstrate that testthat::test_local() (and devtools::test()) fail for function master_fct2() (when the package is not installed but merely loaded with devtools), but the function runs without any problems when called by the user or when tested with testthat::test_dir().

It is noteworthy that the problem appears to come from a call to dplyr::summarize() in the worker function. master_fct1() calls a different worker function that does not use dplyr::summarize(), and that testthat::test_local() has no problems with that function.

Errors

Using testthat::test_local()

tryCatch(
  expr = { testthat::test_local() },
  error = function(e) {
    print(conditionMessage(e))
  }
)
## ✓ |  OK F W S | Context
## ⠏ |   0       | functions                                                       ⠋ |   1       | functions                                                       ⠹ |   3       | functions                                                       ⠦ |   6 1     | functions                                                       x |   6 1     | functions [3.0 s]
## ────────────────────────────────────────────────────────────────────────────────
## Error (test_functions.R:20:3): master_fct2 performs as expected
## Error: 5 nodes produced errors; first error: there is no package called ‘demo’
## Backtrace:
##  1. demo::master_fct2(5) test_functions.R:20:2
##  2. parallel::clusterApplyLB(cl = cl, x = 1:n, fun = worker_fct2) /home/lutz/demo/R/functions.R:42:2
##  3. parallel:::dynamicClusterApply(cl, fun, length(x), argfun)
##  4. parallel:::checkForRemoteErrors(val)
## ────────────────────────────────────────────────────────────────────────────────
## 
## ══ Results ═════════════════════════════════════════════════════════════════════
## Duration: 3.1 s
## 
## [ FAIL 1 | WARN 0 | SKIP 0 | PASS 6 ]
## [1] "Test failures"

Using devtools::test()

tryCatch(
  expr = { devtools::test() },
  error = function(e) {
    print(conditionMessage(e))
  }
)
## ℹ Loading demo

## ℹ Testing demo

## ✓ |  OK F W S | Context
## ⠏ |   0       | functions                                                       ⠹ |   3       | functions                                                       ⠦ |   6 1     | functions                                                       x |   6 1     | functions [2.4 s]
## ────────────────────────────────────────────────────────────────────────────────
## Error (test_functions.R:20:3): master_fct2 performs as expected
## Error: 5 nodes produced errors; first error: there is no package called ‘demo’
## Backtrace:
##  1. demo::master_fct2(5) test_functions.R:20:2
##  2. parallel::clusterApplyLB(cl = cl, x = 1:n, fun = worker_fct2) /home/lutz/demo/R/functions.R:42:2
##  3. parallel:::dynamicClusterApply(cl, fun, length(x), argfun)
##  4. parallel:::checkForRemoteErrors(val)
## ────────────────────────────────────────────────────────────────────────────────
## 
## ══ Results ═════════════════════════════════════════════════════════════════════
## Duration: 2.5 s
## 
## [ FAIL 1 | WARN 0 | SKIP 0 | PASS 6 ]

No errors

Using testthat::test_dir()

devtools::load_all()
## ℹ Loading demo
testthat::test_dir("tests/testthat/")
## ✓ |  OK F W S | Context
## ⠏ |   0       | functions                                                       ⠹ |   3       | functions                                                       ⠦ |   7       | functions                                                       ✓ |   8       | functions [2.0 s]
## 
## ══ Results ═════════════════════════════════════════════════════════════════════
## Duration: 2.0 s
## 
## [ FAIL 0 | WARN 0 | SKIP 0 | PASS 8 ]

Direct function call

devtools::load_all()
## ℹ Loading demo
master_fct2(5L)
## [[1]]
##   x y
## 1 1 1
## 
## [[2]]
##     x   y
## 1 1.5 2.5
## 
## [[3]]
##   x        y
## 1 2 4.666667
## 
## [[4]]
##     x   y
## 1 2.5 7.5
## 
## [[5]]
##   x  y
## 1 3 11

About

No description, website, or topics provided.

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages