pythontdd测试命名_python unittest 加载测试用例名称实现不是test开头的

纯属无聊忽然想到,想修改后unittest会执行以amize开头的case

方法1

修改源码loader.py

'''

loader.py

'''

class TestLoader(object):

....

testMethodPrefix = 'test' #修改成amize就会变成只加载amize开头的

方法2

利用继承的方法

#a 如果用defaultTestLoader.discover 加载case就如下:

class MyTestLoader(unittest.TestLoader):

testMethodPrefix = 'amize' #修改成amize

defaultTestLoader = MyTestLoader()

suites = defaultTestLoader.discover('../testcase', '*.py')

runner = unittest.TextTestRunner()

runner.run(suites)

#b 如果用main()直接执行的:

class MyTestLoader(unittest.TestLoader):

testMethodPrefix = 'amize'

defaultTestLoader = MyTestLoader()

main = unittest.TestProgram

main(testLoader=defaultTestLoader)

方法3

看到HTMLTestRunner里面的用法

# Note: Reuse unittest.TestProgram to launch test. In the future we may

# build our own launcher to support more specific command line

# parameters like test title, CSS, etc.

class TestProgram(unittest.TestProgram):

"""

A variation of the unittest.TestProgram. Please refer to the base

class for command line parameters.

"""

def runTests(self):

# Pick HTMLTestRunner as the default test runner.

# base class's testRunner parameter is not useful because it means

# we have to instantiate HTMLTestRunner before we know self.verbosity.

if self.testRunner is None:

self.testRunner = HTMLTestRunner(verbosity=self.verbosity)

unittest.TestProgram.runTests(self)

main = TestProgram

##############################################################################

# Executing this module from the command line

##############################################################################

if __name__ == "__main__":

main(module=None)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值