我目前正在尝试对某个程序运行一些测试,但突然间我不断得到同样的错误,无论我运行它是什么,不管是我要测试的程序,基本教程文件,空文件还是没有。错误是:
File "/usr/local/bin/py.test", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 38, in main
config = _prepareconfig(args, plugins)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 117, in _prepareconfig
pluginmanager=pluginmanager, args=args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
_MultiCall(methods, kwargs, hook.spec_opts).execute()
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
return _wrapped_call(hook_impl.function(*args), self.execute)
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
wrap_controller.send(call_outcome)
File "/usr/local/lib/python2.7/dist-packages/_pytest/helpconfig.py", line 28, in pytest_cmdline_parse
config = outcome.get_result()
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
_reraise(*ex) # noqa
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
self.result = func()
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
res = hook_impl.function(*args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 852, in pytest_cmdline_parse
self.parse(args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 957, in parse
self._preparse(args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 918, in _preparse
self.pluginmanager.load_setuptools_entrypoints("pytest11")
File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 501, in load_setuptools_entrypoints
plugin = ep.load()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2088, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/local/lib/python2.7/dist-packages/pytest_bdd/__init__.py", line 3, in <module>
from pytest_bdd.steps import given, when, then
File "/usr/local/lib/python2.7/dist-packages/pytest_bdd/steps.py", line 43, in <module>
from .feature import parse_line, force_encode
File "/usr/local/lib/python2.7/dist-packages/pytest_bdd/feature.py", line 37, in <module>
from . import exceptions
File "/usr/local/lib/python2.7/dist-packages/pytest_bdd/exceptions.py", line 65, in <module>
@six.python_2_unicode_compatible
AttributeError: 'module' object has no attribute 'python_2_unicode_compatible'
我在pytest中找不到任何与此bug有关的内容,尽管它似乎发生在使用六个模块的其他程序中。我尝试重新安装六和pytest,但到目前为止没有运气。有什么问题以及如何解决?
以下是print(six.__file__, dir(six))
的结果:
('/usr/lib/python2.7/dist-packages/six.pyc',
['BytesIO', 'Iterator', 'MAXSIZE', 'Module_six_moves_urllib',
'Module_six_moves_urllib_error', 'Module_six_moves_urllib_parse',
'Module_six_moves_urllib_request', 'Module_six_moves_urllib_response',
'Module_six_moves_urllib_robotparser', 'MovedAttribute', 'MovedModule',
'PY2', 'PY3', 'StringIO', '_LazyDescr', '_LazyModule', '_MovedItems',
'__author__', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '__version__', '_add_doc', '_func_closure', '_func_code',
'_func_defaults', '_func_globals', '_import_module', '_iteritems',
'_iterkeys', '_iterlists', '_itervalues', '_meth_func', '_meth_self',
'_moved_attributes', '_urllib_error_moved_attributes',
'_urllib_parse_moved_attributes', '_urllib_request_moved_attributes',
'_urllib_response_moved_attributes', '_urllib_robotparser_moved_attributes',
'add_metaclass', 'add_move', 'advance_iterator', 'b', 'binary_type',
'byte2int', 'callable', 'class_types', 'create_bound_method', 'exec_',
'get_function_closure', 'get_function_code', 'get_function_defaults',
'get_function_globals', 'get_method_function', 'get_method_self',
'get_unbound_function', 'indexbytes', 'int2byte', 'integer_types',
'iterbytes', 'iteritems', 'iterkeys', 'iterlists', 'itervalues', 'moves',
'next', 'operator', 'print_', 'remove_move', 'reraise', 'string_types',
'sys', 'text_type', 'types', 'u', 'unichr', 'with_metaclass'])
答案 0 :(得分:1)
缺少python_2_unicode_compatible
以及_iteritems
,_itervalues
,......的存在表明您使用的是旧版本的Python Six。
确切地说,python_2_unicode_compatible
中引入了pip
。
您可以使用virtualenv
和function doPostAjax(requestURL,formData,callback){
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var jText = JSON.parse(xmlhttp.responseText);
callback(jText);
}else if(xmlhttp.readyState==4 && xmlhttp.status!=200){
handleError(xmlhttp.status);
disableAjaxLoadingImageDiv();
}
}
xmlhttp.open("POST",requestURL,true);
xmlhttp.setRequestHeader("Cache-Control", "no-cache");
xmlhttp.send(formData);
}
安装更新版本。