Pytest-django: How to use test only models

Created on 22 Dec 2015  路  1Comment  路  Source: pytest-dev/pytest-django

I am trying to test a custom field that I wrote. To do so, I have some models I wrote, just for the test cases. Is it possible to have py.test migrate these models before tests that require them?

Most helpful comment

You can add a test specific app which contains the models, and then add it to INSTALLED_APPS in your testsuite.

This is what django-rest-framework does for instance:
https://github.com/tomchristie/django-rest-framework/blob/498ce85f34a9b32eb46e2317ceda9a5c127b2153/tests/models.py
https://github.com/tomchristie/django-rest-framework/blob/498ce85f34a9b32eb46e2317ceda9a5c127b2153/tests/conftest.py#L38

It does not have to live under the tests itself, as long as the test app is available for your tests.

>All comments

You can add a test specific app which contains the models, and then add it to INSTALLED_APPS in your testsuite.

This is what django-rest-framework does for instance:
https://github.com/tomchristie/django-rest-framework/blob/498ce85f34a9b32eb46e2317ceda9a5c127b2153/tests/models.py
https://github.com/tomchristie/django-rest-framework/blob/498ce85f34a9b32eb46e2317ceda9a5c127b2153/tests/conftest.py#L38

It does not have to live under the tests itself, as long as the test app is available for your tests.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ryankask picture ryankask  路  5Comments

ojake picture ojake  路  6Comments

aljosa picture aljosa  路  8Comments

tolomea picture tolomea  路  4Comments

AndreaCrotti picture AndreaCrotti  路  5Comments