-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Use withr to not change global state #829
Conversation
Codecov Report
@@ Coverage Diff @@
## main #829 +/- ##
=======================================
Coverage 55.04% 55.04%
=======================================
Files 124 124
Lines 15388 15388
=======================================
Hits 8470 8470
Misses 6918 6918 |
@IndrajeetPatil Can I add multiple withr::with_environment(
new.env(),
m <- lm(...)
test_that("1", {
...
})
test_that("2", {
...
})
test_that("3", {
...
})
) |
Yes, but IINM you'd need to do something like this: withr::with_environment(
new.env(),
code = {
m <- lm(...)
test_that("1", {
...
})
test_that("2", {
...
})
test_that("3", {
...
})
}
) |
Cool! This should resolve our scoping issues, and probably also the random test order thing. |
You could do that, or maybe a better approach is to create a new environment in each test and test the expectations within this scope. For example, see https://github.com/r-lib/withr/blob/0c5254ebc74590e80cc0056303d74b049b943920/tests/testthat/test-namespace.R#L70-L87 |
This is what I would normally do, but if you look at the test structure of insight, e.g. https://github.com/easystats/insight/blob/main/tests/testthat/test-lm.R, I would need to re-fit the model every time again for each test then (in those cases where we use |
Maybe add back the removed "random test order" check? |
I think that check should work once we addressed the scoping issues using withr, so I'll do that after the withr-work is done. |
Fixes easystats/easystats#388