我想编写一个套件测试,我有一个模块正确运行单元测试,但我打算添加更多模块并立即测试它们,所以我编码了以下代码:Python套件测试不运行测试
#main.py
import unittest
from test.Services import TestOS
if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTests(TestOS.TestOS())
unittest.TextTestRunner().run(suite)
TestOS.py
import unittest
from app.Services.OS import OS
class TestOS(unittest.TestCase):
os = OS()
def setUp(self):
pass
def tearDown(self):
pass
def testOSName(self):
self.assertEquals(self.os.getPlatform(), 'Windows')
def testOSVersion(self):
self.assertEquals(self.os.getVersion(), '7')
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()
它运行后,我得到这样的输出:
Finding files... done.
Importing test modules ... done.
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
它没有没有找到任何测试,我的代码有什么问题?
包括在您的文章你的测试代码。 – 2012-08-10 21:31:42
@BrendenBrown完成! – dextervip 2012-08-10 21:37:27