[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:
		
							parent
							
								
									1e7bb8ca99
								
							
						
					
					
						commit
						d8e5e63235
					
				| 
						 | 
					@ -43,6 +43,9 @@ def adddefaultoptions(config):
 | 
				
			||||||
               action="store", dest="keyword", default='',
 | 
					               action="store", dest="keyword", default='',
 | 
				
			||||||
               help="only run test items matching the given (google-style) "
 | 
					               help="only run test items matching the given (google-style) "
 | 
				
			||||||
                    "keyword expression."),
 | 
					                    "keyword expression."),
 | 
				
			||||||
 | 
					        Option('-q', '--start-on',
 | 
				
			||||||
 | 
					               action='store', dest='start_on', default='',
 | 
				
			||||||
 | 
					               help="start from first test matching given keyword expression"),
 | 
				
			||||||
        Option('-l', '--showlocals',
 | 
					        Option('-l', '--showlocals',
 | 
				
			||||||
               action="store_true", dest="showlocals", default=False,
 | 
					               action="store_true", dest="showlocals", default=False,
 | 
				
			||||||
               help="show locals in tracebacks (disabled by default)."),
 | 
					               help="show locals in tracebacks (disabled by default)."),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,7 +8,13 @@ class Session(object):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    def __init__(self, config): 
 | 
					    def __init__(self, config): 
 | 
				
			||||||
        self._memo = []
 | 
					        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): 
 | 
					    def shouldclose(self): 
 | 
				
			||||||
        return False 
 | 
					        return False 
 | 
				
			||||||
| 
						 | 
					@ -39,6 +45,9 @@ class Session(object):
 | 
				
			||||||
        if option.executable and option.usepdb:
 | 
					        if option.executable and option.usepdb:
 | 
				
			||||||
            raise ValueError, "--exec together with --pdb not supported."
 | 
					            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): 
 | 
					    def start(self, colitem): 
 | 
				
			||||||
        """ hook invoked before each colitem.run() invocation. """ 
 | 
					        """ hook invoked before each colitem.run() invocation. """ 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -100,11 +109,13 @@ class Session(object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def run(self, colitem): 
 | 
					    def run(self, colitem): 
 | 
				
			||||||
        if self.config.option.collectonly and isinstance(colitem, py.test.collect.Item): 
 | 
					        if self.config.option.collectonly and isinstance(colitem, py.test.collect.Item): 
 | 
				
			||||||
            return 
 | 
					            return
 | 
				
			||||||
        if isinstance(colitem, py.test.collect.Item): 
 | 
					        if isinstance(colitem, py.test.collect.Item):
 | 
				
			||||||
            colitem._skipbykeyword(self.config.option.keyword)
 | 
					            colitem._skipbykeyword(self.keyword)
 | 
				
			||||||
 | 
					            if self.config.option.start_on:
 | 
				
			||||||
 | 
					                self.keyword = ""
 | 
				
			||||||
        res = colitem.run() 
 | 
					        res = colitem.run() 
 | 
				
			||||||
        if res is None: 
 | 
					        if res is None:
 | 
				
			||||||
            return Passed() 
 | 
					            return Passed() 
 | 
				
			||||||
        elif not isinstance(res, (list, tuple)): 
 | 
					        elif not isinstance(res, (list, tuple)): 
 | 
				
			||||||
            raise TypeError("%r.run() returned neither "
 | 
					            raise TypeError("%r.run() returned neither "
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -81,6 +81,16 @@ namecontent = [
 | 
				
			||||||
                assert 42 == 43 
 | 
					                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('''
 | 
					    ('testspecial_importerror.py', py.code.Source('''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,8 @@ implied_options = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
conflict_options = ('--looponfailing --pdb',
 | 
					conflict_options = ('--looponfailing --pdb',
 | 
				
			||||||
                    '--dist --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():
 | 
					def test_conflict_options():
 | 
				
			||||||
| 
						 | 
					@ -95,7 +96,18 @@ class TestKeywordSelection:
 | 
				
			||||||
            assert len(l) == 1
 | 
					            assert len(l) == 1
 | 
				
			||||||
            assert l[0][0].name == 'test_2'
 | 
					            assert l[0][0].name == 'test_2'
 | 
				
			||||||
            l = session.getitemoutcomepairs(Skipped)
 | 
					            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: 
 | 
					class TestTerminalSession: 
 | 
				
			||||||
    def mainsession(self, *args): 
 | 
					    def mainsession(self, *args): 
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue