【问题标题】:HTMLTestRunner ImportErrorHTMLTestRunner 导入错误
【发布时间】:2015-10-31 10:16:18
【问题描述】:

我是 selenium + python 的新手。

当我包含 htmltestrunner 来生成报告时,我遇到了一个问题。我正在使用 Python3.4。

以下是我的代码,如果我做的事情与我应该做的不同,请告诉我。

class TestOfReport(unittest.TestCase):

def setUp(self):
    self.driver=webdriver.Firefox()
    self.base_url="https://www.google.co.in/"
    self.driver.implicitly_wait(30)
    self.verificationErrors = []
    self.accept_next_alert = True

def test_TestOfReport(self):
    driver=self.driver
    driver.get(self.base_url)
    driver.maximize_window()
    driver.find_element_by_id("sb_ifc0").send_keys("selenium webdriver")
    driver.find_element_by_name("btnK").click()
    self.assertIn("Google",driver.title)

def tearDown(self):
    self.driver.quit()
    self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
HTMLTestRunner.main()

错误:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensio
ns\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 1
06, in exec_file
    exec_code(code, file, global_variables)
  File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensio
ns\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 8
2, in exec_code
    exec(code_obj, global_variables)
  File "c:\users\documents\visual studio 2013\Projects\TestOfR
eport\TestOfReport\TestOfReport.py", line 10, in <module>
    import HTMLTestRunner
  File "C:\Python34\lib\site-packages\HTMLTestRunner.py", line 94, in <module>
    import StringIO
ImportError: No module named 'StringIO'

【问题讨论】:

    标签: python python-3.x selenium test-runner


    【解决方案1】:

    StringIOcStringIO 模块已从 Python-3.x 中删除。相反,导入io 模块并使用io.StringIODoc link.

    from io import StringIO
    

    【讨论】:

      猜你喜欢
      • 2015-03-02
      • 2017-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-10
      • 1970-01-01
      • 1970-01-01
      • 2018-09-12
      相关资源
      最近更新 更多