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

+2 votes

[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
• 170 points
2,916 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

+1 vote
0 answers

Automation test scripts are failing in linux

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

May 28, 2021 in Software Testing by Sri
• 3,190 points
529 views
+1 vote
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,190 points
1,323 views
+1 vote
2 answers

What are the advantages of Functional Testing?

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

answered Sep 1, 2020 in Software Testing by Sri
• 3,190 points
1,360 views
+1 vote
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,190 points
1,437 views
+1 vote
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,140 points
1,054 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP