Django: Best way to unit-test an abstract model

后端 未结 13 1343
一个人的身影
一个人的身影 2020-12-24 12:28

I need to write some unit tests for an abstract base model, that provides some basic functionality that should be used by other apps. It it would be necessary to define a mo

13条回答
  •  無奈伤痛
    2020-12-24 12:59

    I came to this problem my self and my solution is on this gist django-test-abstract-models

    you can use it like this:

    1- subclass your django abstract models

    2- write your test case like this:

    class MyTestCase(AbstractModelTestCase):
        self.models = [MyAbstractModelSubClass, .....]
        # your tests goes here ...
    

    3- if you didn't provide self.models attribute it will search the current app for models in the path myapp.tests.models.*

提交回复
热议问题