allmodules.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """Use the AllModules plugin by passing ``--all-modules`` or setting the
  2. NOSE_ALL_MODULES environment variable to enable collection and execution of
  3. tests in all python modules. Normal nose behavior is to look for tests only in
  4. modules that match testMatch.
  5. More information: :doc:`../doc_tests/test_allmodules/test_allmodules`
  6. .. warning ::
  7. This plugin can have surprising interactions with plugins that load tests
  8. from what nose normally considers non-test modules, such as
  9. the :doc:`doctest plugin <doctests>`. This is because any given
  10. object in a module can't be loaded both by a plugin and the normal nose
  11. :class:`test loader <nose.loader.TestLoader>`. Also, if you have functions
  12. or classes in non-test modules that look like tests but aren't, you will
  13. likely see errors as nose attempts to run them as tests.
  14. """
  15. import os
  16. from nose.plugins.base import Plugin
  17. class AllModules(Plugin):
  18. """Collect tests from all python modules.
  19. """
  20. def options(self, parser, env):
  21. """Register commandline options.
  22. """
  23. env_opt = 'NOSE_ALL_MODULES'
  24. parser.add_option('--all-modules',
  25. action="store_true",
  26. dest=self.enableOpt,
  27. default=env.get(env_opt),
  28. help="Enable plugin %s: %s [%s]" %
  29. (self.__class__.__name__, self.help(), env_opt))
  30. def wantFile(self, file):
  31. """Override to return True for all files ending with .py"""
  32. # always want .py files
  33. if file.endswith('.py'):
  34. return True
  35. def wantModule(self, module):
  36. """Override return True for all modules"""
  37. return True