Python3 htmltestrunner.py importerror:no module named ' Stringio ' solution:

Source: Internet
Author: User

Full text reprint to: http://www.cnblogs.com/testyao/p/5658200.html

Python3 htmltestrunner.py importerror:no module named ' Stringio ' solution:

1. The reason is that the official website is Python2 Grammar written, crossing manually changed the official website htmltestrunner.py to Python3 syntax:

Reference: http://bbs.chinaunix.net/thread-4154743-1-1.html

: http://tungwaiyip.info/software/HTMLTestRunner.html

Modified: Http://pan.baidu.com/s/1dEZQ0pz (lazy people directly download it)

2. Revision Summary:

Line 94th, change import Stringio to import IO

Line No. 539, change self.outputbuffer = Stringio.stringio () to Self.outputbuffer = Io. Stringio ()

Line No. 642, if not Rmap.has_key (CLS): modified to If not CLS 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, ' \ntime Elapsed:%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.

Execute script code:

#-*-Coding:utf-8-*-#引入webdriver和unittest所需要的包from Selenium import webdriverfrom selenium.webdriver.common.by Import Byfrom Selenium.webdriver.common.keys Import keysfrom selenium.webdriver.support.ui import Selectfrom Selenium.common.exceptions Import nosuchelementexceptionfrom selenium.common.exceptions Import Noalertpresentexceptionimport UnitTest, Time, re# introduced Htmltestrunner package import Htmltestrunner class Baidu (unittest. TestCase): #初始化设置 def setUp (self): Self.driver = Webdriver. Firefox () self.driver.implicitly_wait () Self.base_url = "http://www.baidu.com/" Self.verificationer        Rors = [] Self.accept_next_alert = True #百度搜索用例 def test_baidu (self): Driver = Self.driver        Driver.get (Self.base_url) driver.find_element_by_id ("kw"). Click () driver.find_element_by_id ("kw"). Clear ()        driver.find_element_by_id ("kw"). Send_keys ("Selenium webdriver") driver.find_element_by_id ("su"). Click () Time.sleep (2) driver.close () def tearDown (self): Self.driver.quit () self.assertequal ([], Self.verificationerr ORS) If __name__ = = "__main__": #定义一个测试容器 test = unittest. TestSuite () #将测试用例, added to the Test Container test.addtest (Baidu ("Test_baidu")) #定义个报告存放的路径, support relative path File_path = "f:\\robottest\\r Esult.html "file_result= Open (File_path, ' WB ') #定义测试报告 runner = Htmltestrunner.htmltestrunner (stream = File_resul T, title = u "Baidu Search test Report", Description = u "use Case execution") #运行测试用例 runner.run (test) File_result.close ()

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 no attribute ' decode '

Go to 766, 772 lines continue to modify (note: 766 lines is UO and 772 lines is the UE, then blind, did not notice these, thought is the same, leading 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, ' \ntime Elapsed:%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))

Python3 htmltestrunner.py importerror:no module named ' Stringio ' solution:

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.