Skip to content

Commit

Permalink
Fix declaration inheritance.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbarrois committed Jun 23, 2014
1 parent 6269fef commit e2ef7c9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion factory/base.py
Expand Up @@ -231,7 +231,7 @@ def contribute_to_class(self, factory,

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)
Expand Down
31 changes: 31 additions & 0 deletions tests/test_using.py
Expand Up @@ -766,6 +766,37 @@ class Meta:
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):
Expand Down

0 comments on commit e2ef7c9

Please sign in to comment.