summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--factory/base.py2
-rw-r--r--tests/test_using.py31
2 files changed, 32 insertions, 1 deletions
diff --git a/factory/base.py b/factory/base.py
index 923c56b..9e07899 100644
--- a/factory/base.py
+++ b/factory/base.py
@@ -231,7 +231,7 @@ class FactoryOptions(object):
self.counter_reference = self._get_counter_reference()
- for parent in self.factory.__mro__[1:]:
+ for parent in reversed(self.factory.__mro__[1:]):
if not hasattr(parent, '_meta'):
continue
self.declarations.update(parent._meta.declarations)
diff --git a/tests/test_using.py b/tests/test_using.py
index e20f949..f18df4d 100644
--- a/tests/test_using.py
+++ b/tests/test_using.py
@@ -766,6 +766,37 @@ class UsingFactoryTestCase(unittest.TestCase):
test_object_alt = TestObjectFactory.build()
self.assertEqual(None, test_object_alt.three)
+ def test_override_inherited(self):
+ """Overriding inherited declarations"""
+ class TestObjectFactory(factory.Factory):
+ class Meta:
+ model = TestObject
+
+ one = 'one'
+
+ class TestObjectFactory2(TestObjectFactory):
+ one = 'two'
+
+ test_object = TestObjectFactory2.build()
+ self.assertEqual('two', test_object.one)
+
+ def test_override_inherited_deep(self):
+ """Overriding inherited declarations"""
+ class TestObjectFactory(factory.Factory):
+ class Meta:
+ model = TestObject
+
+ one = 'one'
+
+ class TestObjectFactory2(TestObjectFactory):
+ one = 'two'
+
+ class TestObjectFactory3(TestObjectFactory2):
+ pass
+
+ test_object = TestObjectFactory3.build()
+ self.assertEqual('two', test_object.one)
+
def test_inheritance_and_sequences(self):
"""Sequence counters should be kept within an inheritance chain."""
class TestObjectFactory(factory.Factory):