How do I make PyCharm show code coverage of programs that use multiple processes?

Let's say I create this simple module and call it MyModule.py:

import threading
import multiprocessing
import time

def workerThreaded():
    print 'thread working...'
    time.sleep(2)
    print 'thread complete'

def workerProcessed():
    print 'process working...'
    time.sleep(2)
    print 'process complete'

def main():
    workerThread = threading.Thread(target=workerThreaded)
    workerThread.start()
    workerProcess = multiprocessing.Process(target=workerProcessed)
    workerProcess.start()
    workerThread.join()
    workerProcess.join()

if __name__ == '__main__':
    main()
prettyPrint();

And then I throw this together to unit test it:

import unittest
import MyModule

class MyModuleTester(unittest.TestCase):
    def testMyModule(self):
        MyModule.main()

unittest.main()

prettyPrint();
(I know this isn't a good unit test because it doesn't actually TEST it, it just runs it, but that's not relevant to my question)

If I run this unit test in PyCharm with code coverage, then it only shows the code inside the workerThreaded() and main() functions as being covered, even though it clearly covers the workerProcessed() function as well.

How do I get PyCharm to include code that was started in a new process process in its code coverage? Also, how can I get it to include the if __name__ == '__main__': block as well?

I'm running PyCharm 2.7.3, as well as Python 2.7.3.

Please sign in to leave a comment.