测试人社区

执行pytest,报错 "can't set attribute"

##来吧,说一个pytest遇到的坑


看到这个图片了把,看到大把的朋友在执行pytest的时候报了这个错,
仔细看会发现
2
这里提到了pytest_sugar这个库,那么经过多方求助,得知这是因为这个库的版本或许不兼容的问题
那么把这个库卸载掉就好了。
在Winshell输入: pip uninstall pytest-sugar 就可以完美解决

把报错贴出来,这样子别人就能通过关键字搜索啦。 具体格式可以看下答疑区置顶帖

安装pytest-sugar插件后,运行pytest xx.py报错,错误代码为:

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/_pytest/main.py", line 187, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/_pytest/config/__init__.py", line 820, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pluggy/hooks.py", line 308, in call_historic
INTERNALERROR>     res = self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytest_sugar.py", line 176, in pytest_configure
INTERNALERROR>     sugar_reporter = SugarTerminalReporter(standard_reporter)
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytest_sugar.py", line 214, in __init__
INTERNALERROR>     self.writer = self._tw
INTERNALERROR> AttributeError: can't set attribute

查找pytest-sugar文档说明如下:


python 2.7、3.4版本应该没问题,newer不知道到底支持到了多少版本,我的python 3.8.2版本是不支持的,按照楼主的方法,把插件卸载即可:

$ pip uninsatll pytest-sugar

感谢楼主,感谢助教 :clap: