Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local_mocked_bindings shows different behaviour devtools::test() vs command line , github, devtools::check #1940

Closed
shug0131 opened this issue Mar 8, 2024 · 2 comments
Labels
reprex needs a minimal reproducible example

Comments

@shug0131
Copy link

shug0131 commented Mar 8, 2024

Using local_mocked_bindings() helped me to finally to solve a thorny testing of a function that used utils::askYesNo. So very impressed overall.

But, I found that it worked as expected in most cases (running on command line an individual test, using devtools::check, on a github action with covr::package_coverage) .

But when I used devtools::test(), it would still show the dialogue and need me to hit return. More curiously, even though I ran two tests (for when I say "Yes" and "No"), the dialogue only appeared once, and I only hit return once.

This might actually be desirable behaviour, but needs some more documentation and explanation.

@hadley
Copy link
Member

hadley commented Apr 17, 2024

Could you provide more details and/or a reprex?

@hadley hadley added the reprex needs a minimal reproducible example label Apr 17, 2024
@shug0131
Copy link
Author

I just tried to reproduce with

dialogue <- function(){
answer=askYesNo(
  msg="Is R better than SAS?"
)
return(answer)
}

and

test_that("reprex for dialogue",{
 my_askYesNo_mock= function(...){TRUE}
 local_mocked_bindings(askYesNo = my_askYesNo_mock)
  expect_true( dialogue() )
}
)

But now devtools::test(), works the same as all the other ways of running the test, with no dialogue or interaction needed.

Only explanation I can suggest is me using an updated version of R ( 4.3.2, with CRAN packages taken from https://p3m.dev/cran/__linux__/jammy/2024-02-28)

Happy to consider this as resolved.

@hadley hadley closed this as completed Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reprex needs a minimal reproducible example
Projects
None yet
Development

No branches or pull requests

2 participants