`m magicmock'可以与python3中的int进行比较吗?
我正在迁移我项目的Python版本(2-> 3)。 测试适用于Python2,但对Python3抱怨,此错误就像
TypeError: '>' not supported between instances of 'MagicMock' and 'int'
在这里一样,
# test_mock.py
try:
from mock import MagicMock
except:
from unittest.mock import MagicMock
def test_mock_func():
a = MagicMock()
b = a.value
if b > 100:
assert True
else:
assert True
只需运行py.test。
这些
MagicMock.__le__ = some_le_method # just not working
MagicMock.__le__.__func__.__code = some_le_method.__func__.__code__ # wrapper_descriptor does not have attribute __func__
I am migrating python's version (2->3) of my project. The tests works fine for python2, but complains for python3, the error is like
TypeError: '>' not supported between instances of 'MagicMock' and 'int'
here is a minimal case
# test_mock.py
try:
from mock import MagicMock
except:
from unittest.mock import MagicMock
def test_mock_func():
a = MagicMock()
b = a.value
if b > 100:
assert True
else:
assert True
just run py.test .
These hacks not work
MagicMock.__le__ = some_le_method # just not working
MagicMock.__le__.__func__.__code = some_le_method.__func__.__code__ # wrapper_descriptor does not have attribute __func__
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该分配
__ GT __
内部b
或a.value
You should assign the
__gt__
insideb
ora.value