This question has been flagged
3 Replies
7927 Views

When testing a model (models.Model), we use the ORM to create instances of the model and make assertions about its behavior. Since an abstract model (models.AbstractModel) can not be created, how do you test an abstract model?

Avatar
Discard
Best Answer

Hi Tyler,

Abstract is a generic model that implements some feature that can then be inherited by regular models in order to make that feature available in them.
So if you want to test abstract model you need to inherit this inside regular model(models.model).
For reference you can look for mail.thread.

Avatar
Discard
Author

It just seems awkward to have to subclass an AbstractModel in order to test it. There ought to be a way to unit test the AbstractModel when it contains logic that will be inherited by other classes.

Best Answer

Usually you create a dummy class that inherits the abstract class and use it for unit testing but in Odoo you don't want test tables in your database. So the trick is to create a distinct module for the sole testing purpose and which you will install on a test database but not on a production database. For example, the mass_mailing application does not have any unit test for its abstract classes. The tests are located in another module called test_mass_mailing which has a models package with some test classes.

Avatar
Discard