python unittest does not execute "if __name__ == '__main__' " problem (Pycharm)

The article is reproduced to: https://www.cnblogs.com/csjd/p/6366535.html

question:

1. After selenium imports the unittest framework and the HtmlReport framework, the HtmlReport is not executed.

2. IDE is Pycharm

 

Suppose the code is:

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"

    #other code

  def tearDown(self):

    print "this is tearDown"

 

if __name__ == '__main__':

  print "this is __name__"

  #unittest.main()

Information found online:

1. When Pycharm runs and imports the unittest framework, the command executed is "Run 'Unittests in XXX'", as shown in the following figure:

2. The execution sequence at this time is: Class->def setup ->def test_1 ->def tearDown

3. If the executed command is "Run XXX", then the class will be executed first, and then "if __name__ == '__main__'" will be executed

4. In the code ""if __name__ == '__main__'" area, right-click "run xxx", please refer to the second link for specific steps (useful solution)

  4.1 First delete the configuration of the file in Pycharm, delete the configuration information of the file under "Edit Configurations" - "Python tests"

 

References:

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

Helpful solution: http://stackoverflow.com/questions/20835466/pycharm-wont-allow-to-run-a-file-shows-run-unittest-option-only

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325215973&siteId=291194637