[svn r41855] Add a bit hackish option which allows to start from selected

keyword test, doesn't work with rsession yet.

--HG--
branch : trunk
This commit is contained in:
fijal 2007-04-03 17:23:00 +02:00
parent 1e7bb8ca99
commit d8e5e63235
4 changed files with 43 additions and 7 deletions

View File

@ -43,6 +43,9 @@ def adddefaultoptions(config):
action="store", dest="keyword", default='',
help="only run test items matching the given (google-style) "
"keyword expression."),
Option('-q', '--start-on',
action='store', dest='start_on', default='',
help="start from first test matching given keyword expression"),
Option('-l', '--showlocals',
action="store_true", dest="showlocals", default=False,
help="show locals in tracebacks (disabled by default)."),

View File

@ -8,7 +8,13 @@ class Session(object):
"""
def __init__(self, config):
self._memo = []
self.config = config
self.config = config
if config.option.start_on:
self.keyword = config.option.start_on
elif config.option.keyword:
self.keyword = config.option.keyword
else:
self.keyword = None
def shouldclose(self):
return False
@ -39,6 +45,9 @@ class Session(object):
if option.executable and option.usepdb:
raise ValueError, "--exec together with --pdb not supported."
if option.keyword and option.start_on:
raise ValueError, "--start-on and --keyword not supported"
def start(self, colitem):
""" hook invoked before each colitem.run() invocation. """
@ -100,11 +109,13 @@ class Session(object):
def run(self, colitem):
if self.config.option.collectonly and isinstance(colitem, py.test.collect.Item):
return
if isinstance(colitem, py.test.collect.Item):
colitem._skipbykeyword(self.config.option.keyword)
return
if isinstance(colitem, py.test.collect.Item):
colitem._skipbykeyword(self.keyword)
if self.config.option.start_on:
self.keyword = ""
res = colitem.run()
if res is None:
if res is None:
return Passed()
elif not isinstance(res, (list, tuple)):
raise TypeError("%r.run() returned neither "

View File

@ -81,6 +81,16 @@ namecontent = [
assert 42 == 43
''')),
('testmore.py', py.code.Source('''
def test_one():
assert 1
def test_two():
assert 1
def test_three():
assert 1
''')),
('testspecial_importerror.py', py.code.Source('''

View File

@ -11,7 +11,8 @@ implied_options = {
conflict_options = ('--looponfailing --pdb',
'--dist --pdb',
'--exec=%s --pdb' % py.std.sys.executable,
'--exec=%s --pdb' % py.std.sys.executable,
'-k xxx -q xxx',
)
def test_conflict_options():
@ -95,7 +96,18 @@ class TestKeywordSelection:
assert len(l) == 1
assert l[0][0].name == 'test_2'
l = session.getitemoutcomepairs(Skipped)
assert l[0][0].name == 'test_1'
assert l[0][0].name == 'test_1'
def test_select_starton(self):
config = py.test.config._reparse([datadir/'testmore.py',
'-q', "test_two"])
session = config._getsessionclass()(config, py.std.sys.stdout)
session.main()
l = session.getitemoutcomepairs(Passed)
assert len(l) == 2
l = session.getitemoutcomepairs(Skipped)
assert len(l) == 1
class TestTerminalSession:
def mainsession(self, *args):