I want to create a factory that will produce a list of dictionaries, and I want to be able to pass an iterable of items to serve as values for one of the items in those dicts, and I want the number of dicts in the list to be equal to the number of the items in the iterable I pass. Here’s what I wrote:
class PostResponseFactory(factory.DictFactory):
indices = (0, 10)
errors = factory.List(
[
factory.SubFactory(PostResponseErrorFactory, index=x)
for x in indices
]
)
class Meta:
exclude = ["indices"]
class Params:
indices = (0, 1)
However, when I try calling the factory with the indices
param, it has no effect (in fact, the Params
are totally ignored).
PostResponseFactory(indices=[2, 4]) # still gives me indices 0 and 10
I tried using SelfAttribute
in either the field or the for-loop, but I get the error that SelfAttribute
is not iterable.
Is there a way to do what I want there?