| 1 | """ | 
|---|
| 2 | This plugin installs a SKIP error class for the SkipTest exception. | 
|---|
| 3 | When SkipTest is raised, the exception will be logged in the skipped | 
|---|
| 4 | attribute of the result, 'S' or 'SKIP' (verbose) will be output, and | 
|---|
| 5 | the exception will not be counted as an error or failure. This plugin | 
|---|
| 6 | is enabled by default but may be disabled with the ``--no-skip`` option. | 
|---|
| 7 | """ | 
|---|
| 8 |  | 
|---|
| 9 | from nose.plugins.errorclass import ErrorClass, ErrorClassPlugin | 
|---|
| 10 |  | 
|---|
| 11 |  | 
|---|
| 12 | class SkipTest(Exception): | 
|---|
| 13 | """Raise this exception to mark a test as skipped. | 
|---|
| 14 | """ | 
|---|
| 15 | pass | 
|---|
| 16 |  | 
|---|
| 17 |  | 
|---|
| 18 | class Skip(ErrorClassPlugin): | 
|---|
| 19 | """ | 
|---|
| 20 | Plugin that installs a SKIP error class for the SkipTest | 
|---|
| 21 | exception.  When SkipTest is raised, the exception will be logged | 
|---|
| 22 | in the skipped attribute of the result, 'S' or 'SKIP' (verbose) | 
|---|
| 23 | will be output, and the exception will not be counted as an error | 
|---|
| 24 | or failure. | 
|---|
| 25 | """ | 
|---|
| 26 | enabled = True | 
|---|
| 27 | skipped = ErrorClass(SkipTest, | 
|---|
| 28 | label='SKIP', | 
|---|
| 29 | isfailure=False) | 
|---|
| 30 |  | 
|---|
| 31 | def options(self, parser, env): | 
|---|
| 32 | """ | 
|---|
| 33 | Add my options to command line. | 
|---|
| 34 | """ | 
|---|
| 35 | env_opt = 'NOSE_WITHOUT_SKIP' | 
|---|
| 36 | parser.add_option('--no-skip', action='store_true', | 
|---|
| 37 | dest='noSkip', default=env.get(env_opt, False), | 
|---|
| 38 | help="Disable special handling of SkipTest " | 
|---|
| 39 | "exceptions.") | 
|---|
| 40 |  | 
|---|
| 41 | def configure(self, options, conf): | 
|---|
| 42 | """ | 
|---|
| 43 | Configure plugin. Skip plugin is enabled by default. | 
|---|
| 44 | """ | 
|---|
| 45 | if not self.can_configure: | 
|---|
| 46 | return | 
|---|
| 47 | self.conf = conf | 
|---|
| 48 | disable = getattr(options, 'noSkip', False) | 
|---|
| 49 | if disable: | 
|---|
| 50 | self.enabled = False | 
|---|
| 51 |  | 
|---|