launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
12.36k stars 1.18k forks source link

`#[sqlx::test]` manage the full lifecycle of the test DB (inside a container) #3270

Open Zizico2 opened 3 weeks ago

Zizico2 commented 3 weeks ago

Describe the solution you'd like Have #[sqlx::test] manage the full lifecycle of the test DB. Currently I'm running my tests using test-containers, so I don't need any externally setup DB. Would this be something that could be incorporated into SQLx itself? Currently I'm using regular #[tokio::test].

Describe alternatives you've considered Have some way to run a setup function, before whatever #[sqlx::test] is doing. This way I could setup the container and maybe set the DATABASE_URL environment variable. It could look like #[sqlx::test(setup=my_setup_function)].

nk9 commented 3 weeks ago

I would also like to use test containers with my SQLx code, so being able to define a fixture to set up the environment before running each test would be great.

nk9 commented 3 weeks ago

This seems to be a duplicate of #3022.

Zizico2 commented 2 weeks ago

I guess not exactly since I propose the direct integration of test-containers