Skip to content
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

Provide public API to call the code generated by #[sqlx::test] without involving the #[sqlx::test] itself #3637

Open
vittorius opened this issue Dec 14, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@vittorius
Copy link

Is your feature request related to a problem? Please describe.
It's not always convenient that #[sqlx::test] invokes the underlying async runtime. And it's a blocker for me having the test function marked with #[test]. It's because when I use harness = false for my custom test suite setup, #[test] functions are skipped by rustc and not included in the test binary.

Describe the solution you'd like
I'd like to:

  1. Have the concerns of "test DB setup + run migrations" and "async runtime start" separated and opt-in for #[sqlx::test]
  2. Have the option to avoid marking the test function with #[test] (when I only need the "test DB setup + run migrations" concern)
  3. Maybe even have a public API that will allow calling this "test DB setup + run migrations" code explicitly, exposing the function generated by #[sqlx::test]

Describe alternatives you've considered
https://github.com/tyrchen/sqlx-db-tester

Additional context
In general, I'm trying to use #[sqlx::test] with a BDD library https://github.com/rust-rspec/rspec. And the current API of #[sqlx::test] doesn't allow me to build a custom test suite with harness = false. My idea was to have a sync top-level function marked with #[tokio::test] to be the "async main", then each test closure will manually invoke the test function generated by #[sqlx::test]

@vittorius vittorius added the enhancement New feature or request label Dec 14, 2024
@titaniumtraveler
Copy link
Contributor

Yeah, I would like that too.
Though in my case it is mostly because I would like to use #[sqlx::test] in doc tests.
(Or having the option to call it manually as you would with tokio::runtime::Builder instead of #[tokio::main])
What the #[test] attribute prevents, as functions marked as #[test] are only compiled in with the test profile, not the doctest profile

Though having looked at sqlx-core::testing, I assume that would require a fair bit of refatoring, because currently every TestFn::run_test() call starts its own runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants