Joh*_*ith 5 python python-2.7 python-3.x
我正在迁移我的项目的 python 版本 (2->3)。测试对 python2 工作正常,但对 python3 抱怨,错误就像
TypeError: '>' not supported between instances of 'MagicMock' and 'int'
Run Code Online (Sandbox Code Playgroud)
这是一个最小的案例
TypeError: '>' not supported between instances of 'MagicMock' and 'int'
Run Code Online (Sandbox Code Playgroud)
赶紧跑 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__
Run Code Online (Sandbox Code Playgroud)
小智 1
您应该分配__gt__
内部b
或a.value
# self is MagicMock itself
b.__gt__ = lambda self, compare: True
# or
a.value.__gt__ = lambda self, compare: True
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2426 次 |
最近记录: |