Debugging warnings in tests with mock database

Apologies in advance, I cannot see how I could produce a minimal working example of this problem...

I'm writing a ELT package and one of the database writing functions that works fine in the normal environment is producing warnings in the testing environment, which uses dittodb::with_mock_db to simulate the database responses.

I get the following three warnings (with backtrace)

The valueargument ofnames<- can't be NULL as of tibble 3.0.0.
The valueargument ofnames<-must have the same length asx as of tibble 3.0.0.
The valueargument ofnames<- can't be empty as of tibble 3.0.0.

They are just warnings, so the function is passing the tests.

The problem is I don't know how to debug these warnings, because they only occur when running the test.

The only thing I've managed so far is to suppress the warnings by enclosing the offending function into three (sic!) expect_warning(expect_warning(expect_warning(..))) wrappers :slight_smile:

But presumably these warnings do require actioning sooner or later, but I don't know how to figure out which part of the code is causing them.

Could you provide some code snippets for what triggers the warnings? Or even better, an example mock file (redactions of the data is fine, but the structure of the file might help me help diagnose what's going on here)


Uff, I had to dig deep deep down to get to the bottom of this one, the offending line of code was as.list(unname(tb)) where tb is a tibble.
This code was repeated several times, but the others were all dataframes, so it worked in all cases except for this one.

Still not clear on why it worked interactively but not in testthat, but this might have something to do with this (for me surprising) behaviour:

> tb <- tibble(a = 1:2)
> unname(tb)
Error in names[old] <- names(x)[j[old]] : replacement has length zero
> as.list(unname(tb))
[1] 1 2

Needless to say using unname(as.list(tb)) not only works, but also makes much more logical sense than my original code.

Thanks for the follow up and detailed explanation! And thanks for all the contributions + issues you've sent to dittodb so far, we really appreciate it!

1 Like

This topic was automatically closed after 45 days. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.