Commit 7a75daa9 authored by Julien Muchembled's avatar Julien Muchembled

qa: new --cov-unit runner option

parent 0ae3482b
......@@ -33,7 +33,8 @@ if filter(re.compile(r'--coverage$|-\w*c').match, sys.argv[1:]):
coverage.neotestrunner = []
from neo.tests import getTempDirectory, __dict__ as neo_tests__dict__
from neo.tests import getTempDirectory, NeoTestBase, Patch, \
__dict__ as neo_tests__dict__
from neo.tests.benchmark import BenchmarkRunner
# list of test modules
......@@ -226,6 +227,9 @@ class TestRunner(BenchmarkRunner):
def add_options(self, parser):
parser.add_option('-c', '--coverage', action='store_true',
help='Enable coverage')
parser.add_option('-C', '--cov-unit', action='store_true',
help='Same as -c but output 1 file per test,'
' in the temporary test directory')
parser.add_option('-f', '--functional', action='store_true',
help='Functional tests')
parser.add_option('-u', '--unit', action='store_true',
......@@ -261,6 +265,8 @@ Environment Variables:
""" % neo_tests__dict__
def load_options(self, options, args):
if options.coverage and options.cov_unit:
sys.exit('-c conflicts with -C')
if not (options.unit or options.functional or options.zodb):
if not args:
sys.exit('Nothing to run, please give one of -f, -u, -z')
......@@ -271,6 +277,7 @@ Environment Variables:
zodb = options.zodb,
verbosity = 2 if options.verbose else 1,
coverage = options.coverage,
cov_unit = options.cov_unit,
only = args,
......@@ -279,6 +286,21 @@ Environment Variables:
only = config.only
# run requested tests
runner = NeoTestRunner(config.title or 'Neo', config.verbosity)
if config.cov_unit:
from coverage import Coverage
cov_dir = runner.temp_directory + '/coverage'
def setUp(orig, self):
self.__coverage = Coverage('%s/%s' % (cov_dir,
def _tearDown(orig, self, success):
del self.__coverage
orig(self, success)
if config.unit:'Unit tests', UNIT_TEST_MODULES, only)
......@@ -552,10 +552,29 @@ class Patch(object):
For patched callables, the new one receives the original value as first
Alternative usage:
def funcToPatch(orig, ...):
The decorator applies the patch immediately.
applied = False
def __new__(cls, patched, **patch):
if patch:
return object.__new__(cls)
def patch(func):
self = cls(patched, **{func.__name__: func})
return self
return patch
def __init__(self, patched, **patch):
(name, patch), = patch.iteritems()
self._patched = patched
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment