summaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-11 22:17:57 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-11 22:22:41 +0100
commitf4100b373418a58dba7ff4f29cfb44df4eca3d15 (patch)
treed0efb5073048bf1f18ab59b5cc7ae4ebcfc51492 /factory
parente8327fcb2e31dd7a9ffc7f53c7a678d1c1135cb2 (diff)
downloadfactory-boy-f4100b373418a58dba7ff4f29cfb44df4eca3d15.tar
factory-boy-f4100b373418a58dba7ff4f29cfb44df4eca3d15.tar.gz
Remove automagic associated class discovery.
Diffstat (limited to 'factory')
-rw-r--r--factory/base.py36
1 files changed, 4 insertions, 32 deletions
diff --git a/factory/base.py b/factory/base.py
index 06730ba..8bb6d95 100644
--- a/factory/base.py
+++ b/factory/base.py
@@ -151,7 +151,6 @@ class FactoryMetaClass(BaseFactoryMetaClass):
to a class.
"""
own_associated_class = None
- used_auto_discovery = False
if FACTORY_CLASS_DECLARATION in attrs:
return attrs[FACTORY_CLASS_DECLARATION]
@@ -161,37 +160,10 @@ class FactoryMetaClass(BaseFactoryMetaClass):
if inherited is not None:
return inherited
- if '__module__' in attrs:
- factory_module = sys.modules[attrs['__module__']]
- if class_name.endswith('Factory'):
- # Try a module lookup
- used_auto_discovery = True
- associated_name = class_name[:-len('Factory')]
- if associated_name and hasattr(factory_module, associated_name):
- warnings.warn(
- "Auto-discovery of associated class is deprecated, and "
- "will be removed in the future. Please set '%s = %s' "
- "in the %s class definition." % (
- FACTORY_CLASS_DECLARATION,
- associated_name,
- class_name,
- ), DeprecationWarning, 3)
-
- return getattr(factory_module, associated_name)
-
- # Unable to guess a good option; return the inherited class.
- # Unable to find an associated class; fail.
- if used_auto_discovery:
- raise Factory.AssociatedClassError(
- FactoryMetaClass.ERROR_MESSAGE_AUTODISCOVERY.format(
- FACTORY_CLASS_DECLARATION,
- associated_name,
- class_name,
- factory_module,))
- else:
- raise Factory.AssociatedClassError(
- FactoryMetaClass.ERROR_MESSAGE.format(
- FACTORY_CLASS_DECLARATION))
+ raise Factory.AssociatedClassError(
+ "Could not determine the class associated with %s. "
+ "Use the FACTORY_FOR attribute to specify an associated class." %
+ class_name)
def __new__(cls, class_name, bases, attrs):
"""Determine the associated class based on the factory class name. Record the associated class