码迷,mamicode.com
首页 > 编程语言 > 详细

python unittest不执行"if __name__ == '__main__' "问题

时间:2017-02-04 23:12:34      阅读:1949      评论:0      收藏:0      [点我收藏+]

标签:char   png   rom   搜索   分享   src   问题:   logs   stc   

问题:

selenium导入unittest框架和HtmlReport框架后,HtmlReport不被执行。

 

假设代码为:

from selenium import webdriver

import unittest

 

class Test(unittest.TestCase):

  print "this is class Test"

  def setup(self):

    print "this is setup"

  def test_1(self):

    print "this is tesecase 1"

    #其他代码

  def tearDown(self):

    print "this is tearDown"

 

if __name__ == ‘__main__‘:

  print "this is __name__"

  #unittest.main()

网上搜索到的资料:

1、Pycharm运行导入unittest框架时,执行的的命令是“Run ‘Unittests in XXX‘ ”,如下图所示:

技术分享

2、此时执行顺序为:Class->def setup ->def test_1 ->def tearDown

3、如果执行的命令为“Run XXX”,那么会先执行class后,就执行“if __name__ == ‘__main__‘ ”

 

参考资料:

http://www.ithao123.cn/content-6035445.html

 

python unittest不执行"if __name__ == '__main__' "问题

标签:char   png   rom   搜索   分享   src   问题:   logs   stc   

原文地址:http://www.cnblogs.com/csjd/p/6366535.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!