-
Notifications
You must be signed in to change notification settings - Fork 41
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
rstest try to use case argument as fixture if preceded by underscore #130
Comments
Try follow: #[template]
#[rstest]
#[case::sites(PostFactory {})]
#[case::user_tag_assignments(UserFactory {})]
pub fn apis<T: Factory>(#[case] api: T) {}
#[apply(apis)]
#[tokio::test]
async fn is_correct<T: Factory>(
#[case] _api: T,
) -> Result<()> {
T::create_entity("name", "id").await?;
} In the first snipped you're mixing compact (old) and attribute (new) syntax. Maybe I need to update Anyway your original syntax is not wrong but force you to use the same name argument for each tests... that was one of motivation that push me to find a newer syntax. |
Interesting, I've updated to use the new syntax but still get the exact same error. I can provide a minimal reproduction repo for testing, if you'd like? |
Yes, thanks!! |
Here you go! Running |
Running cargo expand on that example shows the following line: fn case_1_users() -> () {
let _api = api::default();
// ... This seems to be the source of the error. |
That seams a bug in #[rstest]
#[case::users(UserFactory {})]
pub fn more<T: Factory>(#[case] _api: T) {
assert_eq!(T::foo(), "foo");
} Trigger the same error. Unfortunately you can just do one of
Both of them are really dirty but I cannot fix it in the next days :( |
Thanks for your help! I'll work around the issue for now. Glad we could pin it down :) |
We have a
Factory
trait for functions that create entities in our database. This trait is implemented for different entities and then applied using rstest_reuse:However, this trait only contains associated functions and no state, so we end up calling the functions in tests using assiciated function syntax (simplified example):
With this, the compiler complains that the
factory
argument is unused. When prefixing it with an underscore, therstest
macro seems to generate invalid code:Is there another way to solve this on our end? I'm open to restructuring the code if there's a better way to do it.
Alternatively, it would be great to have support for unused arguments in rstest_reuse templates.
The text was updated successfully, but these errors were encountered: