未解决的导入:HTMLTestRunner

时间:2015-01-05 07:28:41

标签: python eclipse selenium-webdriver pydev

我正在未解析的导入:HTMLTestRunner

我的代码

import random
import unittest
import HTMLTestRunner

class TestSequenceFunctions(unittest.TestCase):

    def setUp(self):
        self.seq = range(10)

    def test_shuffle(self):
        # make sure the shuffled sequence does not lose any elements
        random.shuffle(self.seq)
        self.seq.sort()
        self.assertEqual(self.seq, range(10))

        # should raise an exception for an immutable sequence
        self.assertRaises(TypeError, random.shuffle, (1,2,3))
    @unittest.skip("Test Skipped1")
    def test_choicep(self):
        element = random.choice(self.seq)
        self.assertTrue(element in self.seq)
    @unittest.skip("Test Skipped2")
    def test_samplep(self):
        with self.assertRaises(ValueError):
            random.sample(self.seq, 20)
        for element in random.sample(self.seq, 5):
            self.assertTrue(element in self.seq)

suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
unittest.TextTestRunner(verbosity=2).run(suite)

outfile = open("/Users/bhanusaa/Downloads/screenshots/", "w")
runner = HTMLTestRunner.HTMLTestRunner(
stream=outfile,title='Test Report',description='This demonstrates the report output by Prasanna.Yelsangikar.')

runner.run(suite)

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

下载了 HTMLTestRunner

并将 HTMLTestRunner.py 文件保存在 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

但仍然出现错误

仅供参考我已经在 eclipse 中配置了所有必需的设置,并且能够成功启动selenium web驱动程序脚本,但是当我尝试导入HTMLTestRunner时IM GETTING未解决的错误

系统信息。 Python 2.7 pydev 2.2 OS MAC

1 个答案:

答案 0 :(得分:1)

使用' pip'安装时,

HTMLTestRunner 似乎有问题。因此,解决方法请遵循以下步骤:

1)从以下网址获取HTMLTestRunner API:https://raw.githubusercontent.com/tungwaiyip/HTMLTestRunner/master/HTMLTestRunner.py

2)保存' HTMLTestRunner.py' at' C:\ Python27 \ Lib'

3)使用以下步骤从命令提示符执行放置的HTMLTestRunner:

  
    

cd c:\ Python27 \ Lib

         

python HTMLTestRunner.py

  

[检查pyc是否创建& Py文件执行&导航到.py文件可能会因您使用的操作系统而异,不用说]

4)确保环境变量设置正确

确认安装成功:

  

python

     

导入HTMLTestRunner

     

返回键