New submission from Zachary Ware:

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

----------
components: Library (Lib)
files: unittest_resources.diff
keywords: patch
messages: 193499
nosy: ezio.melotti, michael.foord, pitrou, r.david.murray, serhiy.storchaka, 
terry.reedy, zach.ware
priority: normal
severity: normal
status: open
title: Add resource management/guarding to unittest
type: enhancement
versions: Python 3.4
Added file: http://bugs.python.org/file31001/unittest_resources.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18526>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to