混合器:创建实例时属性错误

时间:2018-08-28 13:54:16

标签: python django tdd pytest

对于TDD,我使用:

pytest==3.7.2 pytest-django==3.4.1 mixer==6.0.1

但是问题是我无法通过混音器创建任何实例。他们显示了一个属性错误:

AttributeError: 'Options' object has no attribute 'private_fields'

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

#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()

完整回溯错误:

================================================== 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 ========================================================

1 个答案:

答案 0 :(得分:0)

  1. 卸载当前的调音台: pip卸载Mixer == 6.0.1
  2. 然后安装最新的调音台:  点安装搅拌机