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

Is it possible to use fixture values in case or value lists? #121

Closed
svenstaro opened this issue May 19, 2021 · 9 comments
Closed

Is it possible to use fixture values in case or value lists? #121

svenstaro opened this issue May 19, 2021 · 9 comments

Comments

@svenstaro
Copy link
Contributor

Hey, I realize I have a somewhat weird case but bear with me.

#[fixture]
pub fn rng() -> StdRng {
    let seed: [u8; 32] = rand::thread_rng().gen();
    let rng = StdRng::from_seed(seed);
    rng
}

#[rstest]
#[case(make_password(&mut rng))]
#[tokio::test]
async fn my_test(
    mut rng: StdRng,
    #[case] password: String,
) -> Result<()> {}

So I want to use the rng() fixture in my_test() but also use the resulting rng value in make_password which provides a value to my case.

This currently doesn't work and I suppose it's not currently intended to work. Is there any chance this could be made to work?

@la10736
Copy link
Owner

la10736 commented May 20, 2021

That not true in general:

#[fixture]
pub fn ppp() -> String {
    "ppp".to_owned()
}

fn fff(s: &str) -> String {
    format!("{}-{}", s, s)
}

#[rstest]
#[case(fff(&ppp))]
fn my_test(ppp: String, #[case] password: String) {}

Compile fine.

The issue here is that you use mut rng: StdRng but in the injecting code I remove mutability because in the standard case you would just use it in your test function but not in injecting code: that means you can have lot warning about this.

I just hacked a solution and it works but I need to shut down all warnings and check if I don't have any regression.

I'll fix it ASAP

@svenstaro
Copy link
Contributor Author

Cool!

@svenstaro
Copy link
Contributor Author

Can you make a patch release with this?

@svenstaro
Copy link
Contributor Author

@la10736 friendly ping :)

@la10736
Copy link
Owner

la10736 commented Aug 1, 2021

Sorry... I missed and forget it.... I'll do a release ASAP

@la10736
Copy link
Owner

la10736 commented Aug 1, 2021

Released... sorry for the delay :(

@svenstaro
Copy link
Contributor Author

Alright, but don't forget the tag! Thanks. :)

@la10736
Copy link
Owner

la10736 commented Aug 1, 2021

I did the tag too...

@svenstaro
Copy link
Contributor Author

Sorry, I must've missed it. Thanks for the work! :)

la10736 added a commit that referenced this issue Mar 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants