Python HTMLTestRunner not generating report

前端 未结 3 1750
闹比i
闹比i 2021-01-17 00:55

I am having an problem in generating html report with HTMLTestRunner. I have created a test suite in a file called TestsSuite.py. Here\'s the code excerpt:

i         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-01-17 01:28

    firstly, I don't think HTMLTestRunner works with Python 3.x... so you are out of luck. But let's assume you are trying in Python 2.7...

    You have a slew of problems. You should really read the docs for unittest and HTMLTestRunner.

    However, Consider this example, which achieves similar in python 2:

    import unittest
    from HTMLTestRunner import HTMLTestRunner
    
    
    class TestFoo(unittest.TestCase):
        def test_foo(self):
            self.assertTrue(True)
    
    
    class TestBar(unittest.TestCase):
        def test_bar(self):
            self.assertFalse(False)
    
    
    if __name__ == '__main__':
        loader = unittest.TestLoader()
        suite = unittest.TestSuite((
            loader.loadTestsFromTestCase(TestFoo),
            loader.loadTestsFromTestCase(TestBar)))
        outfile = file('Report.html', 'w')
        runner = HTMLTestRunner(stream=outfile,
                                verbosity=2,
                                title='LinkedIn Report',
                                description='This is a demo report')
        runner.run(suite)
    

提交回复
热议问题