From d8e5e63235336d2e7fb5962fa08d956568f1a2ad Mon Sep 17 00:00:00 2001 From: fijal Date: Tue, 3 Apr 2007 17:23:00 +0200 Subject: [PATCH] [svn r41855] Add a bit hackish option which allows to start from selected keyword test, doesn't work with rsession yet. --HG-- branch : trunk --- py/test/defaultconftest.py | 3 +++ py/test/session.py | 21 ++++++++++++++++----- py/test/testing/setupdata.py | 10 ++++++++++ py/test/testing/test_session.py | 16 ++++++++++++++-- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/py/test/defaultconftest.py b/py/test/defaultconftest.py index e3f3e2dc2..24bb5da2b 100644 --- a/py/test/defaultconftest.py +++ b/py/test/defaultconftest.py @@ -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)."), diff --git a/py/test/session.py b/py/test/session.py index 556ac3289..5673816d1 100644 --- a/py/test/session.py +++ b/py/test/session.py @@ -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 " diff --git a/py/test/testing/setupdata.py b/py/test/testing/setupdata.py index 167add692..79c0be964 100644 --- a/py/test/testing/setupdata.py +++ b/py/test/testing/setupdata.py @@ -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(''' diff --git a/py/test/testing/test_session.py b/py/test/testing/test_session.py index 42cf8d2d9..2238d2f7a 100644 --- a/py/test/testing/test_session.py +++ b/py/test/testing/test_session.py @@ -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):