Unit testing abstract models in Django and factoryboy
I had to test an abstract model recently and I also wanted to take advantage of factoryboy while I was at it. However, a slight problem arose – I could not use it due to the way factories are defined:
FACTORY_FOR requires the model class to be defined and present in the database upfront. This is not the case since I was not dealing with a concrete models and tables for abstract models are not created.
The first question that I was asked was:
Why on earth would you test an abstract model? To be clear – I don’t want to test the model itself – I want to test its methods and I want to do it before they are potentially overriden.