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 | |
---|
9 | from nose.plugins.errorclass import ErrorClass, ErrorClassPlugin |
---|
10 | |
---|
11 | |
---|
12 | class DeprecatedTest(Exception): |
---|
13 | """Raise this exception to mark a test as deprecated. |
---|
14 | """ |
---|
15 | pass |
---|
16 | |
---|
17 | |
---|
18 | class Deprecated(ErrorClassPlugin): |
---|
19 | """ |
---|
20 | Installs a DEPRECATED error class for the DeprecatedTest exception. Enabled |
---|
21 | by default. |
---|
22 | """ |
---|
23 | enabled = True |
---|
24 | deprecated = ErrorClass(DeprecatedTest, |
---|
25 | label='DEPRECATED', |
---|
26 | isfailure=False) |
---|
27 | |
---|
28 | def options(self, parser, env): |
---|
29 | """Register commandline options. |
---|
30 | """ |
---|
31 | env_opt = 'NOSE_WITHOUT_DEPRECATED' |
---|
32 | parser.add_option('--no-deprecated', action='store_true', |
---|
33 | dest='noDeprecated', default=env.get(env_opt, False), |
---|
34 | help="Disable special handling of DeprecatedTest " |
---|
35 | "exceptions.") |
---|
36 | |
---|
37 | def configure(self, options, conf): |
---|
38 | """Configure plugin. |
---|
39 | """ |
---|
40 | if not self.can_configure: |
---|
41 | return |
---|
42 | self.conf = conf |
---|
43 | disable = getattr(options, 'noDeprecated', False) |
---|
44 | if disable: |
---|
45 | self.enabled = False |
---|