Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Factory Boy Create vs create_batch

I am learning django test and i found django factory boy library very helpfull for writing testcase but one thing i am not getting..

forexample my one of Factory name is BlogFactory

so i notice, most of the people use this like this: BlogFactory.create() and some people use it like this.. BlogFactory.create_batch() I am not getting difference between it..

What is different between create and create_batch ?


1 Answers

  • create() is for mocking a single instance of a class.
  • create_batch(size, ...) is for mocking multiple instances.

The create_batch method of a factory cannot be called without parameters as create(), since size is required by design (see the docs link above).

like image 197
wencakisa Avatar answered Sep 06 '26 19:09

wencakisa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!