2 qq 24487695 qq_24487695 于 2016.01.29 18:16 提问

首先呢__name__为什么不等于 __main__,每次运行都会运行两边类中的test

import unittest
from Selenium.Controller import Report
import HTMLTestRunner
global i
i = 1

class MyTestCase(unittest.TestCase):
def test_something(self):
global i
i+=1
print i
self.assertEqual(True, True)

def test_quick(self):
    i_list = [1,3,6,34,23,12,5,8,19,9,0,10,11,15]
    print i_list

if name == 'TestReport':
print 'run main'
u = unittest.TestSuite()
u.addTest(MyTestCase('test_something'))
u.addTest(MyTestCase('test_quick'))
# test = unittest.makeSuite(MyTestCase)

filename = "D:/test5.html"
fp = file(filename, 'wb')

runner = HTMLTestRunner.HTMLTestRunner(
    stream=fp,
    title='longbin',
    description='Run cases in '+'longbin'+',for results please refer to below table')
# runner.run(u)

输出结果
Testing started at 18:15 ...

run main

..

Time Elapsed: 0:00:00
[1, 3, 6, 34, 23, 12, 5, 8, 19, 9, 0, 10, 11, 15]
3

Process finished with exit code 0

求大神帮助,,帮助

1个回答

oyljerry
oyljerry   Ds   Rxr 2016.01.29 20:06

要求你的py模块是python解释器的主文件调用。不然就是作为模块加载,调用你的顶层类

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!