Reputation: 2570
I want to test a custom field.
How can I create a (dummy) model just for testing?
e.g.:
import pytest
from django.db import models
from ..fields import Percentage100Field
class DummyModel(models.Model):
percentage = Percentage100Field()
@pytest.mark.django_db
def test_percentage_100_field():
d = DummyModel.objects.create(percentage=19)
Upvotes: 2
Views: 922
Reputation: 2570
1) Create a test setting file
from .settings import *
INSTALLED_APPS += ["myapp.tests"]
2) Create a pytest.ini file to use the new settings.py file:
[pytest]
addopts = --ds=path.to.test_settings
3) Create a myapp/test/Models.py file with all your models
4) Now all models in the Test folder will automatically be created.
Upvotes: 2