【发布时间】:2011-04-01 15:58:33
【问题描述】:
我收到错误:ValueError:需要超过 2 个值才能解压 当我现在运行单元测试时,有 2 次失败和 1 次跳过 现在据我所知
lambda i: get_error_count(self._error_lookup, i))源码第142行是方法
对于测试,错误,错误捕获:其中有一行代码:
计数 = get_error_count(i)参考 Python 3.0 有点像这样。可以绑定多余的值 (作为列表)到最后一个变量:
a,b,*c = [1,2,3,4,5]
将导致 c 包含 [3,4,5]。
在 Python 2.x 中,你不能直接这样做,但你应该可以 创建一个函数来延长或缩短参数的输入元组 到正确的长度,以便您可以这样做:
a,c,b = 修复(1,2) d,e,f = 修复(1,2,3,4)但是,该函数不知道左侧的长度 序列,因此它必须作为额外参数或硬参数传入 编码。
所以
计数 = get_error_count(i) 仅使用一个变量,其中 def get_error_count(查找,索引): 承担 2我应该使用什么作为第二个变量?解决这个问题?
谢谢, -卡马尔。
-------------------- >> 开始捕获标准输出
\ test_many_errors.test_assert_one ...失败 test_many_errors.test_one ...好的 test_many_errors.test_assert_two ... 错误 test_many_errors.test_two ...好的 test_many_errors.test_value_one ...错误 test_many_errors.test_value_two ...跳过:(,ValueError(),) test_many_errors.test_good_one ...好的 test_many_errors.test_good_two ...好的
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/Current/bin/nosetests", line 10, in <module>
sys.exit(run_exit())
File "/Library/Frameworks/Python.framework/Versions/6.3/lib/python2.6/site-packages/nose/core.py", line 117, in __init__
**extra_args)
File "/Library/Frameworks/Python.framework/Versions/6.3/lib/python2.6/unittest.py", line 817, in __init__
self.runTests()
File "/Library/Frameworks/Python.framework/Versions/6.3/lib/python2.6/site-packages/nose/core.py", line 196, in runTests
result = self.testRunner.run(self.test)
File "/Library/Frameworks/Python.framework/Versions/6.3/lib/python2.6/site-packages/nose/core.py", line 63, in run
result.printErrors()
File "/NOSE_TRIM/nosetrim-read-only/nosetrim/nosetrim.py", line 136, in printErrors
lambda i: get_error_count(self._error_lookup, i))
File "/NOSE_TRIM/nosetrim-read-only/nosetrim/nosetrim.py", line 142, in printErrorList
for test, err, capt in errors:
ValueError: need more than 2 values to unpack
/
--------------------- >> 结束捕获的标准输出
在 1.263 秒内运行 3 次测试
【问题讨论】:
标签: python