python - Why is factory_boy superior to using the ORM directly in tests? -


I do not know why fancy Beeber is liked directly in the Digengo test to make an ORM / model instance. And the factory_boy website is too little to explain the benefits of using it.

It is understood as the choice of fixtures, which is difficult to manage, slow down, etc.

But, why not make the necessary model examples for the test?

If completely replaced by DB in the factory, then it is okay, I think that lot will be useful in this case, but the factory boy made it The Django model examples still interact with the database.

There is support for another potential profit sequence, but it is not difficult to create sequence / sample data without the need of a factory boy.

In all, I'm not actually seeing any use while using a factory boy, versus items / models to make examples directly.

I hope that I am missing something clearly!

Yes, you can make your test data directly by using the DJENGO ORM, but factories And factory_boy In particular, there are advantages to remember and use:

  • A good, clean and readable way to your model factories: / P>

      class case factory (Factory Factory): FACTORY_FOR = Model. CAS number = factory. Equation (lambda n: '1021- {0}'. Format (n)) Create_date = datetime.datetime.now ()  
  • This class-based approach The ability to make another benefit is

  • / li>
  • Clear Class
  • sequence s (as you mentioned) helps to make the data more "dynamic".
  • Decorator - Sometimes you do not want to send a signal when doing a test

Actually, factory_boy is there to create test data Instead, to avoid writing "Helper" functions, it introduces a nice and easy-to-use interface.

Ask yourself: Why is the rearwing wheel particularly a tool for the job?

See also:

  • (Presentation of Carl Mayer)

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -