Home > other >  After executing the test cases, an error, don't know where is wrong, have a great god help don&
After executing the test cases, an error, don't know where is wrong, have a great god help don&

Time:11-27

After executing the test cases, an error, don't know where is wrong, have a great god help don't look at it?
 
The import requests
The import unittest
The import OS
The import time
The import sys
The from HTMLTestRunner import HTMLTestRunner


Class AddFile (unittest. TestCase) :

Def addFile (self, pid, cname) :
Url='https://webapi.115.com/files/add'
The header={
'the user-agent' : 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36 115 browser/13.0.0 '}
Cookie={
'cookies' :' acw_tc=784 e2ca715906270849083403e4526dea21825ed693b2174d77b4f052244d4; UID=593103455 _a1_1590628294; CID=a372b3a2a4835637db65773b5d003817; SEID=f9308c546fe8c23268964cd7f3ff4bf020abb4ef7f7419b3c4b662761e7279ac041058ad29e78ebe719f0bc1600c16c564e6eb6df5bce9f93dd996b9 '
}
Param={' pid, pid, 'cname: cname}

Resp=requests. Post (url=url, headers=headers, cookies=cookie, data=https://bbs.csdn.net/topics/param)
Result=resp. Json ()
# print (result)
If the result [' state '] is True:
Self. AssertIs (result [' state '], True)
Print (result [' state '], 'added folder success! ')
The else:
Self. AssertIs (result [' state '], False)
Print (result [' error '])

# test add folder name already exists, failed to add
Def test_addFile1 (self) :
Self. The addFile (0, 'obsession')

# test add folder name does not exist, you can add a
normalDef test_addFile2 (self) :
The self. The addFile (0, 'through interface automation add folder)


If __name__=="__main__ ':
# structure test set
Suite=unittest. TestSuite ()
# add test cases
Suite. AddTest (AddFile (' test_addFile1))
Suite. AddTest (AddFile (' test_addFile2))

# for current execution time
# date=time. Strftime (' Y - m - % d % %)
Time=time. Strftime (' % % Y - m - m - H - % d % % % S ')
# test
Path='./report/'
# judgment test report of the definition of save the path exists, does not exist, create
If not OS. Path. The exists (path) :
OS. Makedirs (path)
The else:
Pass
# define file name
Filename=path + time + '_report. HTML'

Report_title=u 'test report'
Desc=u 'interface automatic test report details:

With the open (filename, 'wb) as report:
Runner=HTMLTestRunner. HTMLTestRunner (stream=report, the title=report_title, description=desc)
Runner. The run (suite)

# close report
Report. The close ()
# unittest. The main ()


After the operation error:
 
"D: \ \ Program Files \ Python \ Python37 \ Python exe" E:/study/Python/115 interface/addFile. Py
. Traceback (the most recent call last) :
The File "E:/study/python/115 interface/addFile. Py", line 64, in & lt; module>
Runner. The run (suite)
The File "D: \ \ Program Files \ Python \ Python37 \ lib \ site - packages \ HTMLTestRunner \ HTMLTestRunner py", line 631, in the run
Self. GenerateReport (test, the result)
The File "D: \ \ Program Files \ Python \ Python37 \ lib \ site - packages \ HTMLTestRunner \ HTMLTestRunner py", line 691, in generateReport
Self. Stream. Write (output)
TypeError: a bytes - like the object is required, not 'STR'

The Process finished with exit code 1

CodePudding user response:

Have imported a layer HTMLTestRunner, report, don't again. HTMLTestRunner

CodePudding user response:

Param=Jon. Dumps (param)
  • Related