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

It would be good to have fixtures with dinamically changed / different scopes #12673

Open
GeorgeFischhof opened this issue Jul 31, 2024 · 2 comments
Labels
topic: fixtures anything involving fixtures directly or indirectly type: question general question, might be closed after 2 weeks of inactivity

Comments

@GeorgeFischhof
Copy link

What's the problem this feature will solve?

I create random users for the tests. I use factories according to https://docs.pytest.org/en/latest/how-to/fixtures.html#factories-as-fixtures

The user creation is quite expensive (in time), so I would like to create only one user for negative test cases, and one for every positive test case when the user state is changed during the test.

My idea was that create user for negative tests with module scope and use function scope for positive ones. But it is not possible. (I duplicated the fixtures with different scopes, but it is not good)

Describe the solution you'd like

I do not know how to solve this

Alternative Solutions

As I wrote this feature request, it got to my mind that there is a class scope, and that can solve this.:
Create a class for negative test cases and one class for each positive, and it solves the issue.

Perhaps documenting this with an example (two class type: one for all negative test cases and several for the positive ones) should be enough / good

BR,
George

Additional context

@GeorgeFischhof
Copy link
Author

Hi,
In the meantime it's got to mind that if I use managed version (closure created, and function returned from fixture) then users will be created for every test function, so the time consuming thing remains.

BR,
George

@The-Compiler
Copy link
Member

This sounds a lot like #1681 to me - unfortunately there was unforeseen trouble with the implementation of that and we needed to revert it again.

@Zac-HD Zac-HD added type: question general question, might be closed after 2 weeks of inactivity topic: fixtures anything involving fixtures directly or indirectly labels Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: fixtures anything involving fixtures directly or indirectly type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants