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