我在新机器(Windows 10)上设置Python(CPython 3.4,64位)。我安装了numpy&鼻子,并通过解释器提示运行numpy.test()以确保一切正常工作:
Running unit tests for numpy
NumPy version 1.9.0
NumPy is installed in C:\Python34\lib\site-packages\numpy
Python version 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:16:31) [MSC v.1600 64 bit (AMD64)]
nose version 1.3.4
----------------------------------------------------------------------
Ran 5162 tests in 36.783s
OK (KNOWNFAIL=10, SKIP=20)
到目前为止一切顺利,但是当我在VS2012上通过PTVS做同样的事情时(我的团队使用TFS进行源代码控制),有错误和测试失败(下面):
Running unit tests for numpy
NumPy version 1.9.0
NumPy is installed in C:\Python34\lib\site-packages\numpy
Python version 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:16:31) [MSC v.1600 64 bit (AMD64)]
nose version 1.3.4
======================================================================
ERROR: test_basic (test_multiarray.TestResize)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\numpy\core\tests\test_multiarray.py", line 2850, in test_basic
x.resize((5, 5))
ValueError: cannot resize an array that references or is referenced
by another array in this way. Use the resize function
======================================================================
ERROR: test_freeform_shape (test_multiarray.TestResize)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\numpy\core\tests\test_multiarray.py", line 2880, in test_freeform_shape
x.resize(3, 2, 1)
ValueError: cannot resize an array that references or is referenced
by another array in this way. Use the resize function
======================================================================
ERROR: test_int_shape (test_multiarray.TestResize)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\numpy\core\tests\test_multiarray.py", line 2862, in test_int_shape
x.resize(3)
ValueError: cannot resize an array that references or is referenced
by another array in this way. Use the resize function
======================================================================
ERROR: test_obj_obj (test_multiarray.TestResize)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\numpy\core\tests\test_multiarray.py", line 2892, in test_obj_obj
a.resize(15,)
ValueError: cannot resize an array that references or is referenced
by another array in this way. Use the resize function
======================================================================
ERROR: test_zeros_appended (test_multiarray.TestResize)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\numpy\core\tests\test_multiarray.py", line 2885, in test_zeros_appended
x.resize(2, 3, 3)
ValueError: cannot resize an array that references or is referenced
by another array in this way. Use the resize function
======================================================================
ERROR: Ticket #950
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\numpy\core\tests\test_regression.py", line 1272, in test_blasdot_uninitialized_memory
x.resize((m, 0))
ValueError: cannot resize an array that references or is referenced
by another array in this way. Use the resize function
======================================================================
FAIL: test_blasdot.test_dot_3args
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\nose\case.py", line 198, in runTest
self.test(*self.arg)
File "C:\Python34\lib\site-packages\numpy\core\tests\test_blasdot.py", line 54, in test_dot_3args
assert_equal(sys.getrefcount(r), 2)
File "C:\Python34\lib\site-packages\numpy\testing\utils.py", line 334, in assert_equal
raise AssertionError(msg)
AssertionError:
Items are not equal:
ACTUAL: 3
DESIRED: 2
======================================================================
FAIL: test_1d (test_indexing.TestMultiIndexingAutomated)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\numpy\core\tests\test_indexing.py", line 940, in test_1d
self._check_single_index(a, index)
File "C:\Python34\lib\site-packages\numpy\core\tests\test_indexing.py", line 859, in _check_single_index
self._compare_index_result(arr, index, mimic_get, no_copy)
File "C:\Python34\lib\site-packages\numpy\core\tests\test_indexing.py", line 875, in _compare_index_result
assert_equal(sys.getrefcount(arr), 3)
File "C:\Python34\lib\site-packages\numpy\testing\utils.py", line 334, in assert_equal
raise AssertionError(msg)
AssertionError:
Items are not equal:
ACTUAL: 4
DESIRED: 3
======================================================================
FAIL: test_multidim (test_indexing.TestMultiIndexingAutomated)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\numpy\core\tests\test_indexing.py", line 922, in test_multidim
self._check_multi_index(self.a, index)
File "C:\Python34\lib\site-packages\numpy\core\tests\test_indexing.py", line 836, in _check_multi_index
self._compare_index_result(arr, index, mimic_get, no_copy)
File "C:\Python34\lib\site-packages\numpy\core\tests\test_indexing.py", line 875, in _compare_index_result
assert_equal(sys.getrefcount(arr), 3)
File "C:\Python34\lib\site-packages\numpy\testing\utils.py", line 334, in assert_equal
raise AssertionError(msg)
AssertionError:
Items are not equal:
ACTUAL: 4
DESIRED: 3
======================================================================
FAIL: test_dot_3args (test_multiarray.TestDot)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\numpy\core\tests\test_multiarray.py", line 3285, in test_dot_3args
assert_equal(sys.getrefcount(r), 2)
File "C:\Python34\lib\site-packages\numpy\testing\utils.py", line 334, in assert_equal
raise AssertionError(msg)
AssertionError:
Items are not equal:
ACTUAL: 3
DESIRED: 2
----------------------------------------------------------------------
Ran 5162 tests in 181.506s
FAILED (KNOWNFAIL=10, SKIP=20, errors=6, failures=4)
Press any key to continue . . .
我运行了我在VS中通过命令行编写的脚本,结果与通过解释器直接运行测试的结果相同,所以我相信我的VS / Python设置中有些不对,而不是脚本本身。问题是什么?
答案 0 :(得分:1)
您的设置没有任何问题。从某种意义上来说,numpy测试似乎是脆弱的,因为它们不能容忍调试器。我不确定那里发生了什么,但似乎涉及sys.getrefcount
的测试,以及依赖于它的语义是特定的(通常只有一个数组的引用)是失败的。
您可以通过使用sys.settrace
注册自己的跟踪功能直接运行解释器来重现此问题,例如:
import sys
def trace_func(f, e, a):
return trace_func
sys.settrace(trace_func)
import numpy
numpy.test()
请注意,您可以从VS运行脚本而无需通过Debug调试它 - >无需调试即可启动。这将为您提供与直接运行解释器相同的结果。