运行PyTest的属性错误
问题描述:
我目前正试图在某个程序上运行一些测试,但突然间,我不断收到相同的错误,不管我运行的是什么,无论是我想测试的程序,基本教程文件,一个空文件或什么都不是。错误是:运行PyTest的属性错误
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'])
答
缺乏python_2_unicode_compatible
和_iteritems
,_itervalues
存在,......表明您使用的是旧版本的Python六。
准确地说,python_2_unicode_compatible
被引入September 2014。
您可以安装pip
和virtualenv
的更新版本。
相同的想法,打印'六'模块版本,并按照重新安装说明 - http://*.com/questions/29164045/error-with-crunchbase-api-wrapper-pycrunchbase –
你确定你正在导入*正确*'六'? 'print(6 .__ file__,dir(6))'(即它在哪里和它里面)显示什么? – jonrsharpe
已被添加到问题 – Slereah