[py-svn] r41855 - in py/trunk/py/test: . testing

fijal at codespeak.net fijal at codespeak.net
Tue Apr 3 17:23:02 CEST 2007


Author: fijal
Date: Tue Apr  3 17:23:00 2007
New Revision: 41855

Modified:
   py/trunk/py/test/defaultconftest.py
   py/trunk/py/test/session.py
   py/trunk/py/test/testing/setupdata.py
   py/trunk/py/test/testing/test_session.py
Log:
Add a bit hackish option which allows to start from selected
keyword test, doesn't work with rsession yet.


Modified: py/trunk/py/test/defaultconftest.py
==============================================================================
--- py/trunk/py/test/defaultconftest.py	(original)
+++ py/trunk/py/test/defaultconftest.py	Tue Apr  3 17:23:00 2007
@@ -43,6 +43,9 @@
                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)."),

Modified: py/trunk/py/test/session.py
==============================================================================
--- py/trunk/py/test/session.py	(original)
+++ py/trunk/py/test/session.py	Tue Apr  3 17:23:00 2007
@@ -8,7 +8,13 @@
     """
     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 @@
         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 @@
 
     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 "

Modified: py/trunk/py/test/testing/setupdata.py
==============================================================================
--- py/trunk/py/test/testing/setupdata.py	(original)
+++ py/trunk/py/test/testing/setupdata.py	Tue Apr  3 17:23:00 2007
@@ -81,6 +81,16 @@
                 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('''
 

Modified: py/trunk/py/test/testing/test_session.py
==============================================================================
--- py/trunk/py/test/testing/test_session.py	(original)
+++ py/trunk/py/test/testing/test_session.py	Tue Apr  3 17:23:00 2007
@@ -11,7 +11,8 @@
 
 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 @@
             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): 


More information about the py-svn mailing list