-
Notifications
You must be signed in to change notification settings - Fork 629
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
Usual Suspects for specific failure modes #483
Comments
I had some errors that occurred via The issue was that there was an object created outside of the tests that was used inside the tests. The object was found in some test cases but could not be found for others. The test code was something link this: form <- mpg ~ .
test_that('lm fit', {
fit <- lm(form, data = mtcars)
# ...
})
# other tests
# fails here
test_that('glm fit', {
fit <- glm(form, data = mtcars)
# ...
}) |
@topepo Can you say anymore about the lesson learned / how you fixed? Is all of the above in a single test file / context? |
I have no idea why the error was occurring. Here are the changes that I made that fixed it. Instead of referencing the formula object, I just added the formula to each call. I think it was the last test case that used To figure it out, I ran Also, oddly, other errors are surfacing using |
As one more
(this line) but EDIT: This seems to be related to |
One other thing... it looks like some installed packages don't load in some situations: via
via
|
@topepo Thank you! Some vague observations. It feels like the formula stuff might be worth pursuing, but would probably require @lionel- and/or @jimhester to sort it out. It seems like it must have to do with environments and I don't claim to understand how all of that is working inside testthat. Re: the second case. This makes sense, though, yes? A plain |
I've had two recent really annoyingly stupid reasons my checks have failed. One recent was where a line-by-line run through the checks was completing just fine, but running devtools::check() was failing on said lines. This despite me having restarted my r-session several times. I was, though, apparently loading a previously working version of the package (I did something and broke it) by a call the the package by library in a side-script I had not noticed had ended up in my R/ folder and was wreaking havoc. Another recent one was when I was rewriting something I had as data to the package, into a function in stead. And the checks were fine, but I had some really really odd issues during checks because of documentation being all wrong. I had forgotten to remove the documentation for the data of the same name as the function, which was overwriting the function documentation, and so the examples were bugging. This last thing is not really a test-thing really, just something that tok me way too much time to see, as I was obsessed by the tests. |
Experiencing a new one today. devtools::test works just fine, but is failing during build check. In this case I think perhaps the culprit is the sequence of packages loading. I need my package to be loaded after another one, as I need a function to mask a function in another package. I know there probably are reasons to not do it this way, but at the moment that is what I need. I've fixed that in the test script by doing
which works fine during test, fails during check. |
@athanasiamo is this package on github? |
yes, but I did realise my mistake in this! I loaded the package in each specific test script, rather that just in the When I started loading the package in testthat.R instead, it is now passing both test and check. |
Thanks for the follow up. This is exactly what this thread is for. I've been a party to other conversations about how/whether to attach other packages in tests. This is something we should offer guidance on. |
I dont know if its me, my system or whatever, but I do some across some odd behaviour from test and check at times. In this case, the tests should be failing, because I did some alterations to the mother-package (ggseg), and am working on making sure this child-package (ggsegExtra) is up-to-date and works with the changes. During
|
@Athanasiamo Alternatively if your functions in |
@jimhester, having the packages loaded in the
Originally posted by @Athanasiamo in #483 (comment) And yes, |
Example of a difference between results seen via |
One more for the compilation: The culprit turned out to be the order of execution! The failing function had The problem is that some other functions used {formula.tools} and thus the package was loaded. This meant that for that point forward, So the moral of the story is that one source of frustration can be side effects created by other tests! All this shenanigans highlighted a potential error in my code since the issue could arise if the user loaded {formula.tools} before running my function. The fix was to check which version of |
This reminds me of a problem I had yesterday — I forgot to export an S3 method. Unexported method are found when using |
We recently had an issue related to different defaults of |
@czeildi Yes, I'd definitely love to hear specifics. |
I created a reprex at https://github.com/czeildi/logiccheckdemo Function: check_equality <- function(x, y) {
all.equal(x, y) == TRUE && TRUE
} Test: test_that("check_equality returns FALSE for non equal arguments", {
expect_false(check_equality(data.frame(x = 3:6, y = 4), data.frame(x = 4:7, y = 5)))
}) What we experience: tests pass
I could not prove that it is related to the above env vars, but should be something similar, because changing It occurs under R 3.6.0 and 3.6.1, tested with latest I realise this example is silly and it is not good practice to use Code passing check_equality <- function(x, y) {
isTRUE(all.equal(x, y)) && TRUE
} |
Yes, you are correct, these environment variables are turned on by
|
@jimhester we should probably add those to the env vars we set in |
They are set in |
I had a situation where a test was passing when I ran |
I should have known better but empty directories are deleted before tests are run in |
@maelle I have basically come to the opinion that any file system work done in tests should happen below the temp directory anyway. So, if you need to stand up a directory, then do stuff to or in it, the affected test(s) should create such a directory explicitly, below tempdir, for themselves (and delete it when they're done). That, in some sense, designs this problem away. Am I generally getting the gist of what you're talking about? |
@jennybc yes! It seems more work at first to do what you're saying but if one chooses laziness one will be punished 😉 |
Recently had a test that failed on |
Another case of package loading order being important as noted by @Athanasiamo in #483 (comment) see jennahamlin/tinselR#17 (in |
@maelle I poked around a little (but not extensively, so could still be wrong.) But that looks more like a user error, i.e. an explicit call to That is, this doesn't seem related to "package loading order" or anything subtle or implicit. Do you agree? It does underscore that S3 generics/methods are an area where it's easy to make a mistake. |
Edit: I got confused, user error indeed |
My experience on nealrichardson/httptest#51 was the opposite of what most of these reports are about--tests passed in I added a GitHub Actions job to catch this: basically a regular workflow but calling |
@nealrichardson Interesting. I recently did a very manual/cumbersome study of the usethis tests, where I wrote certain conditions (e.g. active usethis project, working directory, etc.) to file at the start and end of each tests to pinpoint sloppy tests that weren't leaving the world as they found it. |
Thanks for this thread! Very interesting stuff here. I am currently stuck with Following some of the advice here, I tried This revealed no errors! Which is great. Another thing so far that I have found helpful was to use A strange thing about all of this is that I can only get these errors locally, and not on GitHub Actions, which are running totally fine (well, pretty much) I'm wondering if there a way for me to replicate the environment that My next step is to try and work out if there's a way to do something with |
I've now started the process of removing I'm trying to document (some of) my process here: https://community.rstudio.com/t/devtools-test-passes-but-devtools-check-does-not/129885 |
Tests that pass during
devtools::test()
but then fail duringdevtools::check()
One cause: files present in source package but that match one of the criteria for auto-Rbuildignore and, therefore, aren't present when tests run at the end of
R CMD check
.from https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Building-package-tarballs
The text was updated successfully, but these errors were encountered: