2

I'm getting Unresolved import: HTMLTestRunner

My code

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)

i had downloaded HTMLTestRunner from http://tungwaiyip.info/software/HTMLTestRunner.html

and saved the HTMLTestRunner.py file in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

but still getting error

FYI i had configured all the required settings in eclipse and able to launch selenium web driver script successfully, but when i'm trying to import HTMLTestRunner IM GETTING unresolved error

SYSTEM INFO. Python 2.7 pydev 2.2 OS MAC

naresh kumar
  • 21
  • 1
  • 3

1 Answers1

2

HTMLTestRunner seems to have issue when installed using 'pip'. So as a workaround follow below steps:

1) Get the HTMLTestRunner API from : https://raw.githubusercontent.com/tungwaiyip/HTMLTestRunner/master/HTMLTestRunner.py

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

3) Execute placed HTMLTestRunner from command prompt with below set of steps:

cd c:\Python27\Lib

python HTMLTestRunner.py

[Check pyc created or not & Py file execution & navigation to .py file may vary depending on OS you are using needless to say]

4) Make sure environment variables set correctly

For confirming the installation successful:

python

import HTMLTestRunner

return key

Unnati Shukla
  • 342
  • 3
  • 15