使用行为框架时的UnicodeDecodeError(1.2.5)

时间:2015-06-03 17:37:18

标签: python python-behave

我有多个功能文件,每个文件至少包含5个方案(测试用例)。 使用Behave Framework提供以下命令

来运行所有功能
behave --junit 

我遇到了异常

Exception UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 22: ordinal not in range(128) 
 Traceback (most recent call last):
 File "myLoc/behave", line 9, in <module>
 load_entry_point('behave==1.2.5', 'console_scripts', 'behave')()
 File "project/lib/python2.7/dist-packages/behave/__main__.py", line 109, in main
 failed = runner.run()
 File "project/lib/python2.7/dist-packages/behave/runner.py", line 672, in run
 return self.run_with_paths()
 File "project/lib/python2.7/dist-packages/behave/runner.py", line 693, in run_with_paths
 return self.run_model()
File "project/lib/python2.7/dist-packages/behave/runner.py", line 483, in run_model
failed = feature.run(self)
File "project/lib/python2.7/dist-packages/behave/model.py", line 523, in run
failed = scenario.run(runner)
File "project/lib/python2.7/dist-packages/behave/model.py", line 882, in run
if not step.run(runner):
File "project/lib/python2.7/dist-packages/behave/model.py", line 1499, in run
output = runner.log_capture.getvalue()
File "project/lib/python2.7/dist-packages/behave/log_capture.py", line 99, in getvalue
return '\n'.join(self.formatter.format(r) for r in self.buffer)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 22: ordinal not in range(128)

发生此异常时,行为不会运行下一个方案(测试)

任何人都可以帮忙修复此问题

1 个答案:

答案 0 :(得分:-1)

以下代码为我工作

import sys
reload(sys)
sys.setdefaultencoding('utf-8')