Python block tests multiple threads

I am testing a web application and I have already written some tests using unittest. There are some necessary steps such as authorization, data exchange that are being tested, and so on. Now I want to check if everything works fine for more than one client. Actually I would like to call the same test for each client on a separate thread, collect all return codes and print result. My question is how do I create threads like this in python? (my ad hoc solution in bash spawns multiple python processes)

Let's consider an example:

import unittest

class Test(unittest.TestCase):

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def testName(self):
        pass

if __name__ == "__main__":
    unittest.main()

      

thread.start_new_thread (unittest.main) # something like this doesn't work

+3


source to share


2 answers


Google, there are a number of predefined options. Nose seems generic.

Otherwise for one of my projects this worked for mine in python 3.3



if __name__ == "__main__":
    from multiprocessing import Process
    procs=[]
    procs.append(Process(target=unittest.main, kwargs={'verbosity':2}))
    procs.append(Process(target=unittest.main, kwargs={'verbosity':2}))
    for proc in procs:
        proc.start()
    for proc in procs:
        proc.join()

      

If you only want to run certain tests, then follow the same steps above, but use the "Suites" from unittest .

+2


source


from multiprocessing import Process import unittest

if __name__ == '__main__':
    p = Process(target=unittest.main, kwargs={'verbosity':2})
    p.start()
    p.join()

Traceback (most recent call last):   File "/home/wasowicz/workspace/Integration_Tests/Tests/main.py", line 6, in <module>
    p.start()   File "/opt/python/x86_64/2.7.3-4/lib/python2.7/multiprocessing/process.py", line 130, in start
    self._popen = Popen(self)   File "/opt/python/x86_64/2.7.3-4/lib/python2.7/multiprocessing/forking.py", line 125, in __init__
    code = process_obj._bootstrap()   File "/opt/python/x86_64/2.7.3-4/lib/python2.7/multiprocessing/process.py", line 268, in _bootstrap
    sys.stderr.write(e.args[0] + '\n') TypeError: unsupported operand type(s) for +: 'bool' and 'str'

      



0


source







All Articles