使用nosetests对webpy程序做单元测试,nosetestswebpy,index.py -
使用nosetests对webpy程序做单元测试,nosetestswebpy,index.py -
index.py ---- web.py主文件
#!/usr/bin/env python# -*- coding: utf-8 -*-import weburls = ("/.*", "hello")app = web.application(urls, globals())class hello: def GET(self): return 'Hello, world!'app.wsgifunc()
nose_test.py ---- 测试文件脚本
#!/usr/bin/env python# -*- coding: utf-8 -*-import indexapp = Noneclass TestIndex(object): def setUp(self): print 'init in class' global app self.app = app def test_index(self): print 'test in class' r = self.app.request('/') assert r.status == '200 OK'def setUp(): print 'init in func' global app app = index.appdef test_index(): print 'test in func' global app r = app.request('/') assert r.status == '200 OK'
测试指令
nosetests nose_test.py -v
nosetests参数说明:
-v:查看测试详细信息-s:显示脚本print信息,默认是print的信息是不输出的nose会查找脚本中 test_命名的函数和Test_命名的类
运行测试脚本时,首先会运行脚本func级别的setUp()函数,
这时候初始化web.py的app
之后会执行class级别的setUp(self)函数,
这时候初始self的app变量为之前初始化的app
#这时候类的__init__()函数是不起作用的
更详细的测试用例可以在test函数中编写,
数据库之类的初始化可以再setUp()函数中编写
如果需要在执行完毕清理资源可以使用tearDown()函数
相关内容
- python调用短信猫控件,发短信,python调用短信控件,我分
- webpy上传大文件代码,webpy上传文件代码,webpy上传普通文
- python里面向shell输出彩色字符串,pythonshell输出,shell里面
- python替换html中的空标签,python替换html标签,html中的空行
- 数独人工算法的python实现,人工算法python,目前只有两个
- python使用os.path和hashlib遍历目录计算所有文件的md5值,
- python过滤字符串中不属于指定集合的字符的类,python字
- python清空linux/unix系统共享内存代码,pythonunix,# -*- cod
- python使用蒙特卡洛方法计算圆周率,python蒙特卡洛,蒙特
- UnicodeDecodeError: 'utf8' codec can't decode
评论关闭