You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I didn't have a "context()" line in any of my tests either. Adding a context() line as the first line of each of my test-*.R scripts fixed this issue for me. No more "Error in x[method] : attempt to apply non-function" error.
Reacted by Patrick Miller, Andrew Marder and Matt Pettis
Is there any way to update the example code in the "Testing" chapter of "R packages" (http://r-pkgs.had.co.nz/tests.html)? It currently has a context call after a library call. This chapter is linked to from the testthatREADME.md so it's a natural place to look for introductory documentation.
library(stringr)
context("String length")
test_that("str_length is number of characters", {
expect_equal(str_length("a"), 1)
expect_equal(str_length("ab"), 2)
expect_equal(str_length("abc"), 3)
})
...
Activity
hadley commentedon Jan 8, 2018
I'd say yes,
context()should always be the first line.hadley commentedon Jan 24, 2018
Re-opening because this bug is super confusing
gm209 commentedon Feb 14, 2018
Hi Chaps,
Did this one get resolved? I am still experiencing this issue.
Cheers
victordavisyieldsio commentedon Feb 22, 2018
I didn't have a "context()" line in any of my tests either. Adding a context() line as the first line of each of my test-*.R scripts fixed this issue for me. No more "Error in x[method] : attempt to apply non-function" error.
add context() to some test files
Add context to all tests
Generate a context if one does not exist
Generate a context if one does not exist
Generate a context if one does not exist
Generate a context if one does not exist (#738)
ctberthiaume commentedon Apr 8, 2018
Is there any way to update the example code in the "Testing" chapter of "R packages" (http://r-pkgs.had.co.nz/tests.html)? It currently has a
contextcall after alibrarycall. This chapter is linked to from thetestthatREADME.mdso it's a natural place to look for introductory documentation.Fix tests to avoid r-lib/testthat#700. Some DRY with RFC3339 datetime…
jimhester commentedon Apr 9, 2018
@ctberthiaume I sent a PR to the book at hadley/r-pkgs#478
Add a "context" to each test file
Christoph999 commentedon May 30, 2018
I had to create a line with context() in each test. This seems to be a bug. (Version 2.0.0)
Many thanks @jimhester !!!
Fablepongiste commentedon Jul 3, 2018
Is it not a bug to have context mandatory ?
Should not that not be allowed to have tests without context ?
Add `context` declarations to tests to avoid obscure failure (r-lib/t…
Put `context` call first in test files, see r-lib/testthat#700
Fixed devtools::test() failing if context() isn't defined
Fixed devtools::test() failing if context() isn't defined (#44)