首页 > 代码库 > 【nose】环境搭建
【nose】环境搭建
http://blog.sina.com.cn/s/blog_65a8ab5d0101fihb.html
环境搭建很简单
https://pypi.python.org/pypi/nose/选择相应的版本下载
tar xzvf nose***
cd nose***
python setup.py install
nosetests 进行测试
若报错如下:
File "/usr/lib/python2.6/dist-packages/nose-1.3.7-py2.6.egg/nose/plugins/manager.py", line 141, in chain
result = meth(*arg, **kw)
File "/usr/lib/python2.6/dist-packages/nose-1.3.7-py2.6.egg/nose/plugins/capture.py", line 74, in formatError
test.capturedOutput = output = self.buffer
File "/usr/lib/python2.6/dist-packages/nose-1.3.7-py2.6.egg/nose/plugins/capture.py", line 112, in _get_buffer
return self._buf.getvalue()
File "/usr/lib64/python2.6/StringIO.py", line 270, in getvalue
self.buf += ‘‘.join(self.buflist)
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe6 in position 1138: ordinal not in range(128)
则是因为编码格式问题,
只需要找到nosetests文件(执行命令的时候会报我的是在/usr/bin/nosetests)
添加内容如下;
reload(sys)
sys.setdefaultencoding(‘utf8‘)
再执行nosetests即可
[root@ip-192-168-1-15:52.77.116.218 bin]#nosetests
----------------------------------------------------------------------
Ran 0 tests in 0.027s
OK
Demo如下 test.py
def setUp():
print ‘function setup‘
def Testfunc1():
print ‘testfunc1‘
assert True
def Testfunc2():
print ‘testfunc2‘
assert True
def tearDown():
print ‘functiontearDown‘
直接在目录下运行nosetests即可看到结果
[root@ip-192-168-1-15:52.77.116.218 nosetest]#nosetests
..
----------------------------------------------------------------------
Ran 2 tests in 0.001s
OK
注意:测试代码保存的文件必须以Test或test开头.然后在该目录下执行nosetests
nose常用参数
【nose】环境搭建