Closed vishen closed 4 years ago
Hi there.
DDF does not have this feature (yet?), but what about to reuse some created instance? Maybe you can create a variable in a base test class that store a created instance. What do you think?
I was doing that, but it was becoming very cumbersome as our models are quite extensive and a lot share similar fields, so I was having to keep track of many variables and add them in as required which was just a pain. I'm not sure if this would be a problem for anyone else though because our models are a mess and not structured very well. I'd be happy to try and implement something if it would be useful for anyone else other than me?
I had an idea now.
You can use the teach
method (old shelve/use_library
) to use always the same model instance.
In this way, DDF won't create a new instance.
For example:
In conftest.py
from ddf import teach, G
limited_instance = G(MyLimitedModel)
teach(MyModel, my_fk_I_want_to_limit_creation=limited_instance)
Then, in your tests:
G(MyModel)
it won't create its FKs...
I need the ability to set the maximum number of instances per model_class, is there a way to do this already?
The the django project I'm using this for is large and complex with lots of relationships every where and I cannot find an easy way to minimise the creating of many instances per model class.