-
Notifications
You must be signed in to change notification settings - Fork 195
Partial fix for upcoming testthat release #2937
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
Conversation
`expect_success()` and `expect_failure()` now test that you have exactly one success/failure and zero failures/successes. I can't quite figure out why the tests are still failing here; maybe it's something to do with recycling? I'm happy to help but I unfortunately I don't know enough about the lintr internals to figure out what's going wrong here. We're planning to submit testthat to CRAN on Nov 10.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2937 +/- ##
==========================================
- Coverage 99.24% 99.24% -0.01%
==========================================
Files 129 129
Lines 7283 7274 -9
==========================================
- Hits 7228 7219 -9
Misses 55 55 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks @hadley! NVM, confirmed |
AFAICT you were only failing the {lintr} check, the main thing was by switching from Thanks for the proactive fix! Your release time is perfectly fine. We are overdue for a release anyway. |
|
Since I submitted this, we realised that we can improve the description of expectations a bit more: https://testthat.r-lib.org/dev/articles/custom-expectation.html#expectation-basics. The key idea is now that your expectation should always return its first input invisibly, regardess of whether it succeeds or fails. I think this probably doesn't apply to lintr (since it's not the sort of expectation that you're likely to chain), but I thought you should know since you're one of the few people who have written a custom expectation AND have seen or interim advice. |
* Partial fix for upcoming testthat release `expect_success()` and `expect_failure()` now test that you have exactly one success/failure and zero failures/successes. I can't quite figure out why the tests are still failing here; maybe it's something to do with recycling? I'm happy to help but I unfortunately I don't know enough about the lintr internals to figure out what's going wrong here. We're planning to submit testthat to CRAN on Nov 10. * simple delint * extract to helper for cyclo complexity * avoid testthat::expect() again * fail() needs return() --------- Co-authored-by: Michael Chirico <chiricom@google.com>
| isTRUE(all.equal(value, check_field)) | ||
| } | ||
| if (!ok) { | ||
| return(testthat::fail(sprintf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For posterity:
The issue here is that fail() doesn't interrupt execution, and essentially we have:
myExpectation <- function(x) {
maybeFail()
succeed()
}
maybeFail <- function(x) {
if (x < 0) fail('negative')
}
expect_failure(myExpectation(-1))So as written (and my own guess) we might think "once fail() is reached, succeed() can't be" but that's not true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think that this could be clearer in https://testthat.r-lib.org/articles/custom-expectation.html ? Maybe I need to say something like this ?
It's easy to think that
fail()is similar tostop()orabort(), because that's how it behaves when you run it interactively in the console. But it can't work this way in tests because tests need to keep running even after failure so that they can report all the failures at once. So in a real testing setup,fail()andpass()work very similarly: they both signal a condition that testhat records and then reports to the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's quite helpful! The examples in the vignette hint at this by always having if/else structure to pass/fail . But as you mentioned, it's deceptively similar to stop/abort, so useful to call out the difference.
expect_success()andexpect_failure()now test that you have exactly one success/failure and zero failures/successes. I can't quite figure out why the tests are still failing here; maybe it's something to do with recycling? I'm happy to help but I unfortunately I don't know enough about the lintr internals to figure out what's going wrong here.We're planning to submit testthat to CRAN on Nov 10.