This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author zach.ware
Recipients ezio.melotti, michael.foord, pitrou, r.david.murray, serhiy.storchaka, terry.reedy, zach.ware
Date 2013-07-22.05:21:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1374470490.47.0.980625465837.issue18526@psf.upfronthosting.co.za>
In-reply-to
Content
Here is an initial attempt at adding resource management/guarding to unittest, a la test.support.requires.

The patch adds 6 new names to unittest.__all__; one function called 'registerResource' which explains itself, one function and one decorator (require and requires, respectively--I'm open to better, more differentiable names) for requiring a resource, and three exceptions (ResourceError for an error and ResourceUnavailable and ResourceDenied for skipping for different reasons).  All of these are implemented in a new unittest.resources module.

Existing modules are changed as follows:

- util.py defines class _BaseSkip(Exception), which ResourceUnavailable inherits from.  ResourceDenied subclasses ResourceUnavailable.
- case.py: SkipTest inherits from _BaseSkip, and _BaseSkip is checked for to mark a test as skipped in _Outcome.testPartExecutor.  Also, TestCase.run is patched to do resource checking for test classes and methods that use the requires decorator.
- loader.py checks for util._BaseSkip instead of case.SkipTest
- main.py adds -u and --use command line options, and use= TestProgram constructor arg.

Tests are added to test_program and a new test_resources.  The doc page is updated appropriately.

The idea behind the departures from the way test.support.requires works is that since this will be used by far more than just the stdlib tests, there will be more than just the resources we use that unittest will need to know about, so there has to be some way to tell it about them--hence 'registerResource'.  Also, to alleviate issues like #18441, I have implemented an easy way to test whether the resource is usable, via the 'checker' argument to registerResource.  Lastly, 'requires' is provided as a decorator for ease of use, though it does add the most complication to the implementation.

I look forward to reviews :)

Thanks,

Zach
History
Date User Action Args
2013-07-22 05:21:31zach.waresetrecipients: + zach.ware, terry.reedy, pitrou, ezio.melotti, r.david.murray, michael.foord, serhiy.storchaka
2013-07-22 05:21:30zach.waresetmessageid: <1374470490.47.0.980625465837.issue18526@psf.upfronthosting.co.za>
2013-07-22 05:21:30zach.warelinkissue18526 messages
2013-07-22 05:21:29zach.warecreate