Enable injecting test runner
We provide a way to define a test runner to use instead the default one (test or async-std::test for async function).
If the given attributes ends with test (the last segment in Path) we don't add test attribute to every test but just leave the provided one.
By this approach we can give a way to use rstest with a lot of other tools without write an ad hoc support.
As example follow code just works without care about what actix_rt::test.
#[rstest(a, b, case (1, 2), case(3, 4))]
#[actix_rt::test]
async fn foo(a: u32, b: u32) {}
- [x] Impl
- [x] Integration test
- [x] Unit tests
- [x] Changelog
- [ ] Docs
Does not work for #[rocket::async_test]
Unfortunately this case is not supported yet.
"Just the attributes that ends with test (last path segment) can be injected."
In this case last path segment is async_test and not just test.
I can try to think to something looser or add some custom rules... I've not a clear position about this :(
This seems to work out of the box already but I'm not sure it works with macros that also require parameters. My use case is wanting to rstest fixtures in conjunction with a sqlx macro: https://docs.rs/sqlx/0.6.1/sqlx/attr.test.html
I'm not sure how the rstest macro works but it looks like it inspects all parameters, is there a way to perhaps skip one? For example:
#[fixture]
async fn my_fixture() -> FixtureStruct { FixtureStruct::default() }
#[rstest]
#[sqlx::test]
async fn test_db(#[future] my_fixture: &FixtureStruct, pool: PgPool) {
// test
}
This will fail because rstest uses the pool parameter but there is no such fixture:
error[E0433]: failed to resolve: use of undeclared crate or module `pool`
|
60 | async fn test_db(#[future] my_fixture: App, pool: PgPool) {
| ^^^^ use of undeclared crate or module `pool`