Skip to content

Commit

Permalink
implement argument ignore feature
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobacis committed Jul 20, 2024
1 parent bb02cfd commit 43f44cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
8 changes: 4 additions & 4 deletions rstest/tests/resources/rstest/ignore_not_fixture_arg.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use rstest::{fixture, rstest};
use rstest::*;

use sqlx::PgPool;
use sqlx::SqlitePool;

struct FixtureStruct {}

#[fixture]
async fn my_fixture() -> FixtureStruct {
fn my_fixture() -> FixtureStruct {
FixtureStruct {}
}

#[rstest]
#[sqlx::test]
async fn test_db(#[future] my_fixture: FixtureStruct, #[ignore] pool: PgPool) {
async fn test_db(my_fixture: FixtureStruct, #[ignore] pool: SqlitePool) {
assert!(true);
}
5 changes: 4 additions & 1 deletion rstest/tests/rstest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,10 @@ fn ignore_underscore_args() {
#[test]
fn ignore_args_not_fixtures() {
let prj = prj("ignore_not_fixture_arg.rs");
prj.add_dependency("sqlx", r#"{version="*", features=["postgres","macros"]}"#);
prj.add_dependency(
"sqlx",
r#"{version="*", features=["sqlite","macros","runtime-tokio"]}"#,
);

let output = prj.run_tests().unwrap();

Expand Down
14 changes: 12 additions & 2 deletions rstest_macros/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,15 @@ fn single_test_case(
attributes.add_trace(format_ident!("trace"));
}
let generics_types = generics_types_ident(generics).cloned().collect::<Vec<_>>();
let inject = inject::resolve_aruments(args.iter(), &resolver, &generics_types);

let (injectable_args, ignored_args): (Vec<_>, Vec<_>) =
args.iter().partition(|arg| match arg.maybe_ident() {
Some(ident) => !info.arguments.is_ignore(ident),
None => true,
});

let inject = inject::resolve_aruments(injectable_args.into_iter(), &resolver, &generics_types);

let args = args
.iter()
.filter_map(MaybeIdent::maybe_ident)
Expand All @@ -273,6 +281,7 @@ fn single_test_case(
} else {
Some(resolve_default_test_attr(is_async))
};

let args = args
.into_iter()
.map(|arg| {
Expand All @@ -283,13 +292,14 @@ fn single_test_case(
}
})
.collect::<Vec<_>>();

let execute = render_test_call(testfn_name.clone().into(), &args, timeout, is_async);
let lifetimes = generics.lifetimes();

quote! {
#test_attr
#(#attrs)*
#asyncness fn #name<#(#lifetimes,)*>() #output {
#asyncness fn #name<#(#lifetimes,)*>(#(#ignored_args,)*) #output {
#test_impl
#inject
#trace_args
Expand Down

0 comments on commit 43f44cf

Please sign in to comment.