Anonymous avatar Anonymous committed 69f3e3c

Add hooks to start coverage for multiprocess forks.

Comments (0)

Files changed (3)

 """Coverage controllers for use by pytest-cov and nose-cov."""
 
+from cov_core_init import UNIQUE_SEP
+import cov_core_init
 import coverage
+import multiprocessing.util
 import socket
 import sys
 import os
 
-from cov_core_init import UNIQUE_SEP
+
+def multiprocessing_start(obj):
+    cov = cov_core_init.init()
+    if cov:
+        multiprocessing.util.Finalize(None,
+                                      multiprocessing_finish,
+                                      args=(cov,),
+                                      exitpriority=1000)
+
+
+def multiprocessing_finish(cov):
+    cov.stop()
+    cov.save()
+
 
 class CovController(object):
     """Base class for different plugin implementations."""
         os.environ['COV_CORE_SOURCE'] = UNIQUE_SEP.join(self.cov_source)
         os.environ['COV_CORE_DATA_FILE'] = self.cov_data_file
         os.environ['COV_CORE_CONFIG'] = self.cov_config
+        multiprocessing.util.register_after_fork(multiprocessing_start, multiprocessing_start)
 
     @staticmethod
     def unset_env():
             cov.erase()
             cov.start()
 
+            return cov
+
     except Exception:
         pass
 ''' % (PTH_FILE_NAME, PTH_FILE)
 
 setuptools.setup(name='cov-core',
-                 version='1.4',
-                 description='plugin core for use by pytest-cov, nose-cov and unittest2-cov',
+                 version='1.5',
+                 description='plugin core for use by pytest-cov, nose-cov and nose2-cov',
                  long_description=open('README.txt').read().strip(),
                  author='Meme Dough',
                  author_email='memedough@gmail.com',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.