python测试unittest/doctest/nose

使用pylint/pyflakes/pep8检查代码风格

使用unittest测试python

cap.py

def just_do_it(text):
    return text.capitalize()


test_cap.py 

import unittest
from python_test import cap

class Test(unittest.TestCase):

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_one_word(self):
        text = 'duck'
        result = cap.just_do_it(text)
        self.assertEqual(result, 'Duck')

if __name__ == '__main__':
    unittest.main()

使用doctest测试python

def just_do_it(text):
    """
    >>> just_do_it('duck')
    'Duck'
    >>> just_do_it('a veriable flock of ducks')
    'A Veriable Flock Of s Ducks'
    """
    from string import capwords
    return capwords(text)

if __name__ =='__main__':
    import doctest
    doctest.testmod()

使用nose测试python

nose安装pip install nose
用法与unittest类似

cap.py

def just_do_it(text):
    return text.capitalize()


test.py 

from python_test import cap
from nose.tools import eq_

def test_one_word():
    text = 'duck'
    result = cap.just_do_it(text)
    eq_(result, 'Duck', )

在终端输入 
nosetests test.py 测试
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值