Python Unit-tests are running twice when run created test suite

+1 vote

[as I created test suite and generate a test report using HTMLTestRunner (Also modified little bit by me) single test run twice.] for that code (test suite) is:

import os
import time
import unittest
from xyz.base import log
from builtins import dir
from xyz.HTMLTestRunner import HTMLTestRunner

from xyz.tests.test.test_01 import TC01

class HTestSuite(unittest.TestCase):
    log.info('Running demo test suite')

    dir = os.getcwd()
    testLoad = unittest.TestLoader()
    log.info(dir)
    test_classes_to_run =[TC01]

    suites_list = []
    for test_class in test_classes_to_run:
        suite = testLoad.loadTestsFromTestCase(test_class)
        suites_list.append(suite)
    log.info(suites_list)
    newSuite = unittest.TestSuite(suites_list)
    log.info(newSuite.countTestCases())
    timestr = time.strftime("_%Y-%m-%d_%H.%M.%S")
    
    resultFile = open(os.path.join(dir, "TestReport"+ timestr + ".html"), "w")
    runner = HTMLTestRunner(stream=resultFile, title='test report', description='Tests Execution Report') 

    runner.run(newSuite)

if __name__ == "__main__":
    unittest.main()
Jul 14, 2020 in Software Testing by Raghvir
• 160 points
512 views

1 answer to this question.

0 votes

Hey @Raghvir, this might probably be because you have the unittest.main that executes it first, and then it would execute by the tesrunner. I don't think you need the HTestSuite in the first place. 

Hope this helps!

answered Jul 14, 2020 by Kim

Related Questions In Software Testing

0 votes
0 answers

Automation test scripts are failing in linux

Hi Team, All test script are running properly ...READ MORE

May 27 in Software Testing by Sri
• 3,050 points
25 views
0 votes
2 answers

What are the different software testing types?

we have 2 types of testing . Functional ...READ MORE

answered Sep 1, 2020 in Software Testing by Sri
• 3,050 points
263 views
0 votes
2 answers

What are the advantages of Functional Testing?

In simple words , expected result and actual ...READ MORE

answered Aug 31, 2020 in Software Testing by Sri
• 3,050 points
370 views
0 votes
2 answers

What are the limitation of Functional testing?

It should mention in ur story only ...READ MORE

answered Sep 1, 2020 in Software Testing by Sri
• 3,050 points
411 views
0 votes
2 answers

Why automation? exactly what we test?

Hey, Automation testing is used to overcome the ...READ MORE

answered May 24, 2019 in Software Testing by Abha
• 28,040 points
202 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,161 views
0 votes
0 answers