python test suite,尝试实现python TestSuite

I have two test cases (two different files) that I want to run together in a Test Suite. I can get the tests to run just by running python "normally" but when I select to run a python-unit test it says 0 tests run. Right now I'm just trying to get at least one test to run correectly.

import usertest

import configtest # first test

import unittest # second test

testSuite = unittest.TestSuite()

testResult = unittest.TestResult()

confTest = configtest.ConfigTestCase()

testSuite.addTest(configtest.suite())

test = testSuite.run(testResult)

print testResult.testsRun # prints 1 if run "normally"

Here's an example of my test case set up

class ConfigTestCase(unittest.TestCase):

def setUp(self):

##set up code

def runTest(self):

#runs test

def suite():

"""

Gather all the tests from this module in a test suite.

"""

test_suite = unittest.TestSuite()

test_suite.addTest(unittest.makeSuite(ConfigTestCase))

return test_suite

if __name__ == "__main__":

#So you can run tests from this module individually.

unittest.main()

What do I have to do to get this work correctly?

解决方案

you want to use a testsuit. So you need not call unittest.main().

Use of testsuit should be like this:

#import usertest

#import configtest # first test

import unittest # second test

class ConfigTestCase(unittest.TestCase):

def setUp(self):

print 'stp'

##set up code

def runTest(self):

#runs test

print 'stp'

def suite():

"""

Gather all the tests from this module in a test suite.

"""

test_suite = unittest.TestSuite()

test_suite.addTest(unittest.makeSuite(ConfigTestCase))

return test_suite

mySuit=suite()

runner=unittest.TextTestRunner()

runner.run(mySuit)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值