首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mixer:创建实例时出现属性错误

Mixer:创建实例时出现属性错误
EN

Stack Overflow用户
提问于 2018-08-28 21:54:16
回答 1查看 202关注 0票数 0

对于TDD,我使用:

代码语言:javascript
复制
pytest==3.7.2 pytest-django==3.4.1 mixer==6.0.1

但问题是我不能通过mixer创建任何实例。他们显示了一个属性错误:

代码语言:javascript
复制
AttributeError: 'Options' object has no attribute 'private_fields'

我的test_models.py和models.py代码:

代码语言:javascript
复制
#test_models.py
import pytest
from mixer.backend.django import mixer
from birdie.models import Post

@pytest.mark.django_db
class TestPost:

    def test_model(self):
        obj = mixer.blend(User) 
        assert obj.pk == 1, 'Should create a post instance'


# models.py

class Post(models.Model):
    body = models.TextField()

完全回溯错误:

代码语言:javascript
复制
================================================== FAILURES ======================================================================
_____________________________________ TestPost.test_model _________________________________________________________________

self = <birdie.tests.test_models.TestPost object at 0x7f719ab99898>

    def test_model(self):

>       obj = mixer.blend(User)

birdie/tests/test_models.py:22: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../.local/share/virtualenvs/tdd_test-D7r9ITf0/lib/python3.5/site-packages/mixer/main.py:566: in blend
    type_mixer = self.get_typemixer(scheme)
../../../.local/share/virtualenvs/tdd_test-D7r9ITf0/lib/python3.5/site-packages/mixer/main.py:585: in get_typemixer
    fake=self.params.get('fake'), factory=self.__factory)
../../../.local/share/virtualenvs/tdd_test-D7r9ITf0/lib/python3.5/site-packages/mixer/main.py:55: in __call__
    cls_type, mixer=mixer, factory=factory, fake=fake)
../../../.local/share/virtualenvs/tdd_test-D7r9ITf0/lib/python3.5/site-packages/mixer/main.py:88: in __init__
    self.__fields = _.OrderedDict(self.__load_fields())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <TypeMixer <class 'django.contrib.auth.models.User'>>

    def __load_fields(self):
>       private_fields = self.__scheme._meta.private_fields
E       AttributeError: 'Options' object has no attribute 'private_fields'

../../../.local/share/virtualenvs/tdd_test-D7r9ITf0/lib/python3.5/site-packages/mixer/backend/django.py:385: AttributeError
--------------------------------------------------- coverage: platform linux, python 3.5.3-final-0 ---------------------------------------------------
Coverage HTML written to dir htmlcov
================================= warnings summary ==================================================================
<undetermined location>
  pytest_funcarg__cov: declaring fixtures using "pytest_funcarg__" prefix is deprecated and scheduled to be removed in pytest 4.0.  Please remove the prefix and use the @pytest.fixture decorator instead.

-- Docs: http://doc.pytest.org/en/latest/warnings.html
========================= 1 failed, 1 warnings in 2.75 seconds ========================================================
EN

回答 1

Stack Overflow用户

发布于 2019-08-20 20:20:29

  1. 卸载当前的混音器: pip uninstall mixer==6.0.1
  2. Then安装最新的混音器: pip安装混音器
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52059605

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档