From d9098a809db170f8ffc52efe3e5c6e7f48aa2893 Mon Sep 17 00:00:00 2001 From: Rich Rauenzahn Date: Tue, 12 Apr 2016 14:57:28 -0700 Subject: Add custom error message when django_get_or_create is missing an input. --- factory/django.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/factory/django.py b/factory/django.py index b3c508c..43434c2 100644 --- a/factory/django.py +++ b/factory/django.py @@ -29,6 +29,8 @@ import types import logging import functools +from . import errors + """factory_boy extensions for use with the Django framework.""" try: @@ -157,6 +159,11 @@ class DjangoModelFactory(base.Factory): key_fields = {} for field in cls._meta.django_get_or_create: + if field not in kwargs: + raise errors.FactoryError( + "django_get_or_create - " + "Unable to find initialization value for '%s' in factory %s" % + (field, cls.__name__)) key_fields[field] = kwargs.pop(field) key_fields['defaults'] = kwargs -- cgit v1.2.3