【nose入门】环境搭建

http://blog.sina.com.cn/s/blog_65a8ab5d0101fihb.html

主要分为四个模块

一 环境搭建

二 demo测试

三 参数说明

四 注意事项

 

一  环境搭建

1 从网站https://pypi.python.org/pypi/nose/选择相应的版本下载 wget url即可下载到服务器对应目录

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常用参数

nosetests  –v :debug模式,看到具体执行情况,推荐大家执行时用这个选项
nose会捕获标准输出,调试的print代码默认不会打印。nosetest  –s 可打开output输出,否则全部通过时不打印stdout。
默认nosetests会执行所有的case,若想单独只执行一个case,执行nosetest --tests 后跟要测试的文件(nosetests后面直接跟文件名,其实也可以直接运行该case)。
nosetests --collect-only -v :不运行程序,只是搜集并输出各个case的名称
nosetests -x  :一旦case失败立即停止,不执行后续case
-w ,指定一个目录运行测试。目录可以是相对路径或绝对路径
nosetest a.py                   运行test_a.py中所有用例
nosetest test_a.py:Testfunc1     运行test_a.py中的Testfunc1用例
 
nosetests--with-coverage代码覆盖率 --- 没有用这个,用的SLOCCount
脚本自动执行并生成xml文件
/usr/local/bin/nosetests -l -d -v --with-id --with-xunit --xunit-file="log/rebroke.xml"  "rebroke"
 
 

转载于:https://www.cnblogs.com/zhaoxd07/p/6269170.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值