source file: /opt/devel/celery/celery/discovery.py
file stats: 14 lines, 12 executed: 85.7% covered
   1. from django.conf import settings
   2. 
   3. 
   4. def autodiscover():
   5.     """Include tasks for all applications in settings.INSTALLED_APPS."""
   6.     return filter(None, [find_related_module(app, "tasks")
   7.                             for app in settings.INSTALLED_APPS])
   8. 
   9. 
  10. def find_related_module(app, related_name):
  11.     """Given an application name and a module name, tries to find that
  12.     module in the application, and running handler' if it finds it.
  13.     """
  14. 
  15.     try:
  16.         module = __import__(app, {}, {}, [related_name])
  17.     except ImportError:
  18.         return None
  19. 
  20.     try:
  21.         related_module = getattr(module, related_name)
  22.     except AttributeError:
  23.         return None
  24. 
  25.     return related_module