How to check fields of a custom Django model?

I am going to subclass Django models and distribute them as a package in PyPI . I like to write unit tests for my code (Γ  la TDD ), but I'm a bit puzzled by how I will write tests for this particular library.

The first thought that came to my mind was to create a Django project that uses my subclasses, and just use the Django testing tools , but it's not very elegant at all. There must be a better way!

Is there a way to somehow load Django for this type of thing? I would appreciate if someone would point me in the right direction. Thanks!

+4
source share
1 answer

Django itself has some tests for subclassing fields; tests have their own models.py , where custom fields are used. You should get the best experience if you look at the actual code yourself

Addition. In order for the models defined in your test package to be detected by django, you need to add the yourapp.test package to INSTALLED_APPS . Django itself has a built-in mechanism so that its own tests are automatically detected and added to INSTALLED_APPS .

+3
source

Source: https://habr.com/ru/post/1398702/


All Articles