Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7347174
  • 博文数量: 1763
  • 博客积分: 18684
  • 博客等级: 上将
  • 技术积分: 16217
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-02 10:28
个人简介

啥也没写

文章分类

全部博文(1763)

文章存档

2023年(44)

2022年(39)

2021年(46)

2020年(43)

2019年(27)

2018年(44)

2017年(50)

2016年(47)

2015年(15)

2014年(21)

2013年(43)

2012年(143)

2011年(228)

2010年(263)

2009年(384)

2008年(246)

2007年(30)

2006年(38)

2005年(2)

2004年(1)

分类: LINUX

2011-09-06 11:57:45

#index.py   ----    web.py主文件
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import web

urls = ("/.*", "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 index

app = None

class 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.app

def test_index():
    print 'test in func'
    global app
    r = app.request('/')
    assert r.status == '200 OK'

 

测试指令

nosetests nose_test.py -v

-v:查看测试详细信息
-s:显示脚本print信息,默认是print的信息是不输出的
nose会查找脚本中 test_*命名的函数和Test_*命名的类
运行测试脚本时,首先会运行脚本func级别的setUp()函数,
这时候初始化web.py的app
之后会执行class级别的setUp(self)函数,
这时候初始self的app变量为之前初始化的app
#这时候类的__init__()函数是不起作用的
更详细的测试用例可以在test函数中编写,
数据库之类的初始化可以再setUp()函数中编写
如果需要在执行完毕清理资源可以使用tearDown()函数

转:

阅读(777) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~