我正在尝试在Python 2.6.6 RHEL 6.10上设置pytest。
正如official change log中指出的,pytest 3.3.0
不支持python 2.6,因此应考虑使用pytest < 3.3
。我可以成功安装pytest=3.2.5
,但是当我执行一个简单测试时,出现以下错误:
Traceback (most recent call last):
File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib64/python2.6/runpy.py", line 34, in _run_code
exec code in run_globals
File "/usr/lib/python2.6/site-packages/pytest.py", line 17, in <module>
raise SystemExit(pytest.main())
File "/usr/lib/python2.6/site-packages/_pytest/config.py", line 57, in main
return config.hook.pytest_cmdline_main(config=config)
File "/usr/lib/python2.6/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File "/usr/lib/python2.6/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/usr/lib/python2.6/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
_MultiCall(methods, kwargs, hook.spec_opts).execute()
File "/usr/lib/python2.6/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
res = hook_impl.function(*args)
File "/usr/lib/python2.6/site-packages/_pytest/main.py", line 127, in pytest_cmdline_main
return wrap_session(config, _main)
File "/usr/lib/python2.6/site-packages/_pytest/main.py", line 111, in wrap_session
config.notify_exception(excinfo, config.option)
File "/usr/lib/python2.6/site-packages/_pytest/config.py", line 936, in notify_exception
excinfo=excinfo)
File "/usr/lib/python2.6/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File "/usr/lib/python2.6/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/usr/lib/python2.6/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
_MultiCall(methods, kwargs, hook.spec_opts).execute()
File "/usr/lib/python2.6/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
res = hook_impl.function(*args)
File "/usr/lib/python2.6/site-packages/_pytest/terminal.py", line 163, in pytest_internalerror
for line in py.builtin.text(excrepr).split("\n"):
File "/usr/lib/python2.6/site-packages/_pytest/_code/code.py", line 664, in __unicode__
self.toterminal(tw)
File "/usr/lib/python2.6/site-packages/_pytest/_code/code.py", line 709, in toterminal
self.reprtraceback.toterminal(tw)
File "/usr/lib/python2.6/site-packages/_pytest/_code/code.py", line 725, in toterminal
entry.toterminal(tw)
File "/usr/lib/python2.6/site-packages/_pytest/_code/code.py", line 748, in toterminal
tw.write("".join(self.lines))
File "/usr/lib/python2.6/site-packages/py/_io/terminalwriter.py", line 250, in write
self._update_chars_on_current_line(msg)
File "/usr/lib/python2.6/site-packages/py/_io/terminalwriter.py", line 262, in _update_chars_on_current_line
current_line = current_line.decode('utf-8', errors='replace')
TypeError: decode() takes no keyword arguments
快速搜索表明decode()
在python 2.7中采用了参数。
如果是这种情况,那么建议在Python 2.6.6中使用哪个版本的pytest?
答案 0 :(得分:0)
pytest == 3.2.5是仍然支持Python 2.6的版本,但是仅仅因为pytest == 3.2.5支持Python 2.6,并不一定意味着它的依赖关系就是在setup.py中指定的库作者所支持的Python。 2.6。
大多数软件包使用大于约束来指定其依赖关系,例如libxxx> = 1.2.3,以确保当依赖库的作者发布依赖关系时,您将自动获得较新版本的依赖关系,但绝不会下载不兼容的较旧版本。在大多数情况下,这很不错,因为它减少了库作者的工作量,但这意味着,如果该依赖库发布了较新的版本,从而放弃了对该依赖库仍支持的特定版本的支持,那么您将在,因为没有不止一个约束可以防止这种情况。
在这种情况下,根据您显示的回溯,拉出的py.io库不支持python 2.6。您需要降级并将py.io固定到仍支持2.6的旧版本。
根据py.io changelog,仍支持Python 2.6的最后一个版本是py.io == 1.4.34。
如果对支持旧版软件很重要,则应创建requirements.txt文件以冻结依赖项列表,而不要依赖于软件包中的自动版本解析。