0

I am trying to run my tests in parallel mode using ThreadPoolExecutor, here is my Runner class

suite = unittest.TestSuite()
    if (options == 'by_method'):
        for object in name:
            for method in dir(object):
                if (method.startswith('test')):
                    suite.addTest(object(method))

    with ThreadPoolExecutor(max_workers=devicesList.__len__()) as executor:
        list_of_suites = list(suite)
        for test in range(len(list_of_suites)):
            test_name = str(list_of_suites[test])
            try:
                executor.submit(unittest.TextTestRunner(verbosity=2).run, list_of_suites[test])
            except:
                pass

And this is my test class

import unittest
class Runner(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        print("setup method")

    def test_deeplinks(self):
        print("test1")

    def test(self):
        print("test2");

    def test4(self):
        print("test 4")

    def test5(self):
        print("test5");

    @classmethod
    def tearDownClass(self):
        print("tear down ")


if __name__ == '__main__':
    # runner = Runner.Runner()
    # runner.parallel_execution(Runner, TestDeeplinks)
    suite = unittest.TestLoader().loadTestsFromTestCase(Runner)
    unittest.TextTestRunner(verbosity=2).run

but my setupClass method is not getting called can anyone please tell what i'm doing here

Love
  • 125
  • 2
  • 13
  • But i want that this method should be called after all tests got executed – Love Jul 29 '20 at 18:39
  • Your code is badly formatted. Please [edit] the question to fix the formatting. Also, please create a minimal example, rather than a maximal one. See how to create a [mcve] – zvone Jul 29 '20 at 18:39
  • @zvone Please check now – Love Jul 30 '20 at 05:24
  • What is the output you get? If you remove the `ThreadPoolExecutor`, do you still have the same problem? – zvone Jul 30 '20 at 07:44
  • Yes if umi run this without threadpoolexecutor it is working fine but i wanted to run this parallely – Love Jul 30 '20 at 07:47
  • @zvone Anything wrong here? – Love Jul 30 '20 at 09:25
  • found 1 thing when i add suite in the run method i.e. run(suite) then the classMethod is executed but in that cases test cases does not execute parallely, but when i remove suite from run method then test cases executed in parallel but classMethod fails to execute @zvone – Love Jul 30 '20 at 11:27

1 Answers1

0

Maybe you need to use setUp() instead of setUpClass()

setUpClass() only runs once per whole class

https://stackoverflow.com/a/23670844/6243764

Brenda S.
  • 146
  • 1