工厂男孩不能从基础工厂继承metaclass:`issubclass`错误

时间:2017-07-04 07:03:50

标签: python python-2.7 metaclass factory-boy

我对工厂男孩很新。我有一个模型,它在对象层次结构中的不同位置创建,并具有不同的属性,具体取决于它的使用方式。在这种情况下,我有一张图片,可以是徽标或个人资料照片。

这很好用:

class ProfileImageBase(factory.Factory):
    mimetype = 'png'
    image    = 'some bytes'

class UserProfileImage(ProfileImageBase):
    class Meta:
        model = models.media_models.ProfileImage
    parent = factory.SubFactory(BasicUser)
    id     = ProfileImage.PROFILE

class MerchantLogoImage(ProfileImageBase):
    class Meta:
        model = models.media_models.ProfileImage
    parent = factory.SubFactory(BasicMerchant)
    id     = ProfileImage.LOGO

不是很干呃?我想将Meta类放在基类中,但这给了我疯狂的错误:

class ProfileImageBase(factory.Factory):
    class Meta:
        model = models.media_models.ProfileImage
    mimetype = 'png'
    image    = 'some bytes'

class UserProfileImage(ProfileImageBase):
    parent = factory.SubFactory(BasicUser)
    id     = ProfileImage.PROFILE

class MerchantLogoImage(ProfileImageBase):
    parent = factory.SubFactory(BasicMerchant)
    id     = ProfileImage.LOGO

这是追溯

Traceback (most recent call last):
  File "/home/sheena/Workspace/Waxed/venvs/wxt_comp/local/lib/python2.7/site-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/home/sheena/Workspace/Waxed/venvs/wxt_comp/local/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/home/sheena/Workspace/Waxed/venvs/wxt_comp/local/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home/sheena/Workspace/Waxed/code/waxed_backend/src/waxed_backend/concerns/pictures/tests/view_tests.py", line 3, in <module>
    from ....models.test_factories.profile_pictures import MerchantLogoImage
  File "/home/sheena/Workspace/Waxed/code/waxed_backend/src/waxed_backend/models/test_factories/profile_pictures.py", line 13, in <module>
    class UserProfileImage(ProfileImageBase):
  File "/home/sheena/Workspace/Waxed/venvs/wxt_comp/local/lib/python2.7/site-packages/factory/base.py", line 114, in __new__
    params=attrs_params,
  File "/home/sheena/Workspace/Waxed/venvs/wxt_comp/local/lib/python2.7/site-packages/factory/base.py", line 232, in contribute_to_class
    self.counter_reference = self._get_counter_reference()
  File "/home/sheena/Workspace/Waxed/venvs/wxt_comp/local/lib/python2.7/site-packages/factory/base.py", line 259, in _get_counter_reference
    and issubclass(self.model, self.base_factory._meta.model)):
TypeError: Error when calling the metaclass bases
    issubclass() arg 1 must be a class

我的问题是:地球上到底发生了什么?我不相信我在做任何新奇事。

0 个答案:

没有答案