When replying to the selenium2+python2.7 of the god of the worm, it was found that the Htmltestrunner module used to generate Htmltestrunner's test report was Python2 syntax. And I am more accustomed to Python3. And I also use the Python3.4 environment, in the Internet to find a lot of information, modified the next htmltestrunner.py
Reference: http://bbs.chinaunix.net/thread-4154743-1-1.html
: http://tungwaiyip.info/software/HTMLTestRunner.html
Htmltestrunner:http://pan.baidu.com/s/1tp3ts after modification
To modify a rollup:
Line 94th, change import Stringio to import IO
Line No. 539, modify Self.outputbuffer = Stringio.stringio () to self.outputbuffer= io. Stringio ()
Line No. 642, if not Rmap.has_key (CLS): modified to If NOTCLS in Rmap:
Line No. 766, change uo = O.decode (' latin-1 ') to UO = E
Line No. 775, change UE = E.decode (' latin-1 ') to UE = E
Line No. 631, change print >> sys.stderr, ' \ntime Elapsed:%s '% (self.stoptime-self.starttime) to print (Sys.stderr, ' \ ntimeelapsed:%s '% (self.stoptime-self.starttime))
Use Htmltestrunner under Python3.4, start, introduce Htmltestrunner module error.
In the Htmltestrunner 94 line, is the use of the Stringio, but Python3, there is no stringio. Instead, it's IO. Stringio. So change this line to import IO
In 539 rows of Htmltestrunner, Self.outputbuffer =stringio.stringio () is modified to Self.outputbuffer = IO. Stringio ()
After the modification, the module was successfully introduced.
After running the test script, the error is found:
File "C:\Python34\lib\HTMLTestRunner.py", line 642, in Sortresult
If not Rmap.has_key (CLS):
So go to line 642 to modify the code:
Continue to error after running:
Attributeerror: ' Str ' object has Noattribute ' decode '
Go to line 766,772 continue to modify (note: 766 lines is UO and 772 lines is the UE, then blind, did not notice these, thought is the same, led to some inexplicable errors, tossing half a day):
Modified to run, found and error:
File "C:\Python34\lib\HTMLTestRunner.py", line 631, in run
Print >> sys.stderr, ' \ntime Elapsed:%s '% (self.stoptime-self.starttime)
typeerror:unsupported operand type (s) for >>: ' Builtin_function_or_method ' and ' _io. Textiowrapper '
Go to 631 to view and discover the only print in the entire program:
Print >> Sys.stderr, ' \ntimeelapsed:%s '% (self.stoptime-self.starttime
This is the 2.x notation, we modify the print to 3.x, the following changes:
Print (Sys.stderr, ' \ntime Elapsed:%s '% (self.stoptime-self.starttime))
Continue running scripts, OK runs successfully
Viewing the specified directory generates the result.html
Click to open the report:
Htmltestrunner Modifying the version of Python3
Tags: python
Original: http://hzqldjb.blog.51cto.com/9587820/1590802
Htmltestrunner Modifying the version of Python3