rust sqlx-cli: how to prepare offline mode for queries in tests

Viewed 488

I use some https://github.com/launchbadge/sqlx query! macros in my tests, and I need to be able to run cargo sqlx prepare for them so my IDE can expand the macros and provide type information (autocomplete, etc.).

But if I just run cargo sqlx prepare, all code behind #[cfg(test)] is ignored.

How can I tell cargo/sqlx to analyse my tests too?

1 Answers

cargo sqlx prepare -- --tests does the trick

(--tests is passed to cargo rustc, which makes it build all tests)

Related