我怀疑我无法正确安装nosetests。 我用easy_install nose - 输出
Searching for nose
Best match: nose 1.0.0
Processing nose-1.0.0-py2.7.egg
nose 1.0.0 is already the active version in easy-install.pth
Installing nosetests-script.py script to C:\Python27\Scripts
Installing nosetests.exe script to C:\Python27\Scripts
Installing nosetests-2.7-script.py script to C:\Python27\Script
Installing nosetests-2.7.exe script to C:\Python27\Scripts
所以看起来安装得很好。但是当我运行nosetests -h
时PS C:\Users\john\code\python> nosetests -h
Traceback (most recent call last):
File "C:\Python27\Scripts\nosetests-script.py", line 9, in <module>
load_entry_point('nose==1.0.0', 'console_scripts', 'nosetests')()
File "C:\Python27\lib\site-packages\nose-1.0.0-py2.7.egg\nose\core.py", line 118, in __init__
**extra_args)
TypeError: __init__() got an unexpected keyword argument 'exit'
我是否错过了设置步骤?
答案 0 :(得分:2)
怪异。在nose/core.py
中,TestProgram
构造函数调用父构造函数,如下所示:
...
extra_args = {}
version = sys.version_info[0:2]
if version >= (2,7) and version != (3,0):
extra_args['exit'] = exit
unittest.TestProgram.__init__(
self, module=module, defaultTest=defaultTest,
argv=argv, testRunner=testRunner, testLoader=testLoader,
**extra_args)
TestProgram
中unittest/main.py
的构造函数接受exit
参数:
class TestProgram(object):
...
def __init__(self, module='__main__', defaultTest=None, argv=None,
testRunner=None, testLoader=loader.defaultTestLoader,
exit=True, verbosity=1, failfast=None, catchbreak=None,
buffer=None):
...
所以......我不知道这个错误是怎么发生的。您是否安装了更多版本的Python?您的测试是否真的使用了适用于Python 2.7的正确unittest
模块?您能看一下unittest\main.py
(C:\Python27
中的某个地方)并查看TestProgram
构造函数,是否有exit
参数?