Open eugene-kulak opened 4 years ago
Hi!
Going this way would require a way to notify the factory that we only want "new instances", never reusing existing ones.
In your example, the issue is twofold:
django_get_or_create
means you want to reuse values from the database.As long as you're combining this two, what you want is impossible: if a previous step has already created 160 entries in the table, and you request a batch of "5 new records", the system would fail - there are only 4 available records left.
The problem
Let's say we have following factory for currency:
then in the test we create few instances:
Proposed solution
create_batch
should count real records and not justcreate
callsExtra notes
The real cause of this I think is the use of
get_or_create
, because it is bad practice in unittesting in general, but unfortunately, I don't see how this can be solved with sequences in factory boy (see problems with resetting all sequences between tests)