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?
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.
Most helpful comment
You can add a test specific app which contains the models, and then add it to
INSTALLED_APPSin 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.