python - Mixer:创建实例时出现属性错误
问题描述
对于 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 ========================================================
解决方案
- 卸载当前的混音器: pip uninstall mixer==6.0.1
- 然后安装最新的混音器:pip install mixer
推荐阅读
- javascript - 为什么 'class' 必须是 JavaScript 中的保留关键字?
- git - 如何将文件夹放到不同的分支?
- android - Android Log.d 打印行号
- node.js - UnhandledPromiseRejectionWarning:错误:在选择器“小部件”处修剪来自:Ionic
- php - Codeigniter 计数注册访客
- installation - ubuntu 18.04上安装opennebula的问题
- python - Multiprocessing.Pool.Map 不做任何事情
- python - PyTorch - 在 torch.sort 之后取回原始张量顺序的更好方法
- angular - 无法设置动态输入字段离子
- javascript - 在浏览器和 react-native 中使用 javascript 提取设备唯一 ID