コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
9989 ビュー

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?

アバター
破棄
最善の回答

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.

アバター
破棄
著作者

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.

最善の回答

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.

アバター
破棄
関連投稿 返信 ビュー 活動
1
12月 22
8236
0
8月 21
4
1
3月 19
18830
3
5月 18
4855
2
11月 16
3654