-
Notifications
You must be signed in to change notification settings - Fork 4
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
Remove the restriction on usability for tests only #3
base: master
Are you sure you want to change the base?
Conversation
You can define the scope on the fixture. This is just helper which is not doing any work. I believe you are using this tool wrong. Can you share your example what are you trying to achieve? |
Hi Michal, If I should just take the example from the module documentation:
The last bullet is probably where it stops making sense in this simple example. The real usecase is more like that the fixture is preparing data in some data store (e.g. database) and the test is querying an application (via an api), which then accesses that data. |
Looking at it again, I probably do not need to remove the assert in use_data. |
This library is about providing data for fixtures, but you should still use fixtures as you need. So if you want to have fixture in module scope to run it only once, you would do something like this:
But then it doesn't make much sense to use it with pytest-data, as if you init Client per module once, you cannot change the data per test. What you could do is to split the init and seeding if its possible. Something like this:
|
I think that your first snippet is where things blow up, because We do use Using the already present approach with |
Anyway, this is just a suggestion resulting from practical use and feel free to decline it if you don't believe it makes sense for the library. |
You are right, the first example cannot probably work, and it is a bit weird too. That's why I think the second option makes more sense. The problem is, if you have a module-scoped fixture and you use_data on multiple test functions, it will not change for every test, and it will be a surprise for you to find there is actually something else than what you expect. Or am I missing anything? Maybe I don't follow how you use exactly use_data and what makes the performance issue? |
In some cases it may be expensive to run fixtures for every test while running them once per module may be good enough.
In order to do that, we had to remove the restrictions that force function scope and
test_
function name prefix.