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

Use fixtures in in cases #172

Open
fhennig opened this issue Dec 19, 2022 · 2 comments
Open

Use fixtures in in cases #172

fhennig opened this issue Dec 19, 2022 · 2 comments

Comments

@fhennig
Copy link

fhennig commented Dec 19, 2022

I have an idea for using fixture in the case macro:

struct TestDependency;  // complex object 

#[fixture]
fn dependency_built_in_one_way() -> TestDependency {
    ...  // long setup
}

#[fixture]
fn dependency_built_in_another_way() -> TestDependency {
    ... // long setup
}

#[rstest]
fn testing_specific_feature(dependency_built_in_one_way: TestDependency) {
    ... // testing something only on the first object
}

// A test that should test a feature on both complex configurations of the dependency
#[rstest]
#[case(dependency_built_in_one_way)]
#[case(dependency_built_in_another_way)]
fn my_test(#[case] dependency: TestDependency) {
    ...
}

That would be useful to me. I could do something similar with cases on the fixture, but then I wouldn't be able to only use one of the built variants in certain tests.

@la10736
Copy link
Owner

la10736 commented Dec 19, 2022

If I remember well the original function is not removed... so you can call it like:

#[rstest]
#[case(dependency_built_in_one_way())]
#[case(dependency_built_in_another_way())]
fn my_test(#[case] dependency: TestDependency) {
    ...
}

There is no way to implement because the procedural macro that expand the tests cannot know nothing about the available fixtures or other symbols that can be available with the same name.

@fhennig
Copy link
Author

fhennig commented Dec 19, 2022

Ah, I forgot to mention that dependency_built_in_one_way has other fixtures it depends on.

There is no way to implement because the procedural macro that expand the tests cannot know nothing about the available fixtures or other symbols that can be available with the same name.

Alright, that is unfortunate.

Thanks for your quick response!

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