我收到未解析的导入: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
操作系统MAC

最佳答案

使用“ pip”安装时,HTMLTestRunner似乎有问题。因此,请按照以下步骤作为解决方法:

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

2)将'HTMLTestRunner.py'保存在'C:\ Python27 \ Lib'中

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


  
    cd c:\ Python27 \ Lib
    
    python HTMLTestRunner.py
  


[检查pyc是否已创建&py文件的执行以及对.py文件的导航可能会有所不同,这取决于您使用的OS,不用多说]

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

要确认安装成功:


  蟒蛇
  
  导入HTMLTestRunner
  
  返回键

关于python - Unresolved 导入:HTMLTestRunner,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27775092/

10-12 17:03