Python about not executing if __name__ = = ' __main__ ': Test module resolution

Source: Internet
Author: User

1. Create a new test script file:

2. Edit the test script

ImportUnitTestImportRequestsImportJSONImportHTMLTestRunnerur1='http://118.178.247.67:8081/systLogonUser/adminLogon.do'Headers= {'Content-type':'application/x-www-form-urlencoded','Referer':'118.178.247.67'}data= {    'UserName': 18200716020 ,    'pwd':'123456Bb',    'Verifycode': 121}r= Requests.post (url=ur1,data=data,headers=headers) Repones=R.textPrint(R.text)Print(R.status_code)classdemotest (unittest. TestCase):deftest_1 (self): Self.assertequals (R.status_code,200)        Print('First case')    deftest_2 (self): Self.assertin ('true', Repones)Print('Article two case')    deftest_3 (self):Print('Article 3rd case')#after the indent is adjusted, the main is not executedif __name__=='__main__':    Print("Start main") Suite=UnitTest. TestSuite () suite.addtest (Demotest ('test_1')) Suite.addtest (Demotest ('test_2')) Suite.addtest (Demotest ('Test_3')) FileName='e:\\test.html'FP= open (filename,'wb+')#here is the quote write is Htmltestrunner, has been error, looking for a half day reason    #runner = Htmltestrunner.htmltestrunner (STREAM=FP, output= ' e:/test.html ', report_title= ' test-results ',                                           #descriptions= ' first Python unittest ')    #runner = Htmltestrunner.htmltestrunner (Stream=fp,report_title=u "Test-results", descriptions=u "first python UnitTest ")Runner = Htmltestrunner.htmltestrunner (STREAM=FP, Title=u"This is my test report title .", Description=u"This is the description of my test case.") Runner.run (Suite) fp.close ()

3, press Add, click Save

4. Test Run Results

Python about not executing if __name__ = = ' __main__ ': Test module resolution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.