ValueError:需要超过2个值才能在Python 2.6.6中解压缩

kam*_*mal 17 python

我收到错误:ValueError:当我现在运行单元测试时需要超过2个值才能解压缩,所以2个失败,一个跳过现在我已经阅读过

lambda i: get_error_count(self._error_lookup, i))

源的第142行是方法

for test, err, capt in errors:

它有代码行:

count = 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 = fix(1,2)
d,e,f = fix(1,2,3,4)

但是,该函数不会知道左侧序列的长度,因此必须作为额外参数传递或硬编码.

所以

count = get_error_count(i)
uses only one variable, where as
def get_error_count(lookup, index):
takes on 2

我应该用什么作为第二个变量?解决这个问题?

谢谢,-Kamal.

-------------------- >>开始捕获stdout << ---------------------

\ test_many_errors.test_assert_one ... FAIL test_many_errors.test_one ... ok test_many_errors.test_assert_two ...错误test_many_errors.test_two ... ok test_many_errors.test_value_one ...错误test_many_errors.test_value_two ...跳过:(,ValueError(), )test_many_errors.test_good_one ... ok test_many_errors.test_good_two ... ok

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
Run Code Online (Sandbox Code Playgroud)

/

--------------------- >>结束捕获的标准输出<< ----------------------


在1.263s中进行3次测试

And*_*ett 20

而不是在你的任务中解包:

a, b, c = do_something()
Run Code Online (Sandbox Code Playgroud)

尝试将结果分配给单个变量并测试其长度:

t = do_something()
# t is now a tuple (or list, or whatever was returned) of results
if len(t) > 2:
    # Can use the third result!
    c = t[2]
Run Code Online (Sandbox Code Playgroud)