deprecated.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. This plugin installs a DEPRECATED error class for the :class:`DeprecatedTest`
  3. exception. When :class:`DeprecatedTest` is raised, the exception will be logged
  4. in the deprecated attribute of the result, ``D`` or ``DEPRECATED`` (verbose)
  5. will be output, and the exception will not be counted as an error or failure.
  6. It is enabled by default, but can be turned off by using ``--no-deprecated``.
  7. """
  8. from nose.plugins.errorclass import ErrorClass, ErrorClassPlugin
  9. class DeprecatedTest(Exception):
  10. """Raise this exception to mark a test as deprecated.
  11. """
  12. pass
  13. class Deprecated(ErrorClassPlugin):
  14. """
  15. Installs a DEPRECATED error class for the DeprecatedTest exception. Enabled
  16. by default.
  17. """
  18. enabled = True
  19. deprecated = ErrorClass(DeprecatedTest,
  20. label='DEPRECATED',
  21. isfailure=False)
  22. def options(self, parser, env):
  23. """Register commandline options.
  24. """
  25. env_opt = 'NOSE_WITHOUT_DEPRECATED'
  26. parser.add_option('--no-deprecated', action='store_true',
  27. dest='noDeprecated', default=env.get(env_opt, False),
  28. help="Disable special handling of DeprecatedTest "
  29. "exceptions.")
  30. def configure(self, options, conf):
  31. """Configure plugin.
  32. """
  33. if not self.can_configure:
  34. return
  35. self.conf = conf
  36. disable = getattr(options, 'noDeprecated', False)
  37. if disable:
  38. self.enabled = False