Commits

Antonio Cuni committed 9ec4ff5

a bit hackish, but add a --filter option to py.test which works similarly to -k, but filters the cpython unittest

Comments (0)

Files changed (2)

lib-python/conftest.py

     group.addoption('--pypy', action="store", type="string",
        dest="pypy",  help="use given pypy executable to run lib-python tests. "
                           "This will run the tests directly (i.e. not through py.py)")
-   
+    group.addoption('--filter', action="store", type="string", default=None,
+                    dest="unittest_filter",  help="Similar to -k, XXX")
+
 option = py.test.config.option 
 
 def gettimeout(): 
             else:
                 status = 'abnormal termination 0x%x' % status
         else:
-            status = os.system("%s >>%s 2>>%s" %(cmd, stdout, stderr))
+            if self.config.option.unittest_filter is not None:
+                cmd += ' --filter %s' % self.config.option.unittest_filter
+            if self.config.option.capture == 'no':
+                status = os.system(cmd)
+            else:
+                status = os.system("%s >>%s 2>>%s" %(cmd, stdout, stderr))
             if os.WIFEXITED(status):
                 status = os.WEXITSTATUS(status)
             else:

lib-python/modified-2.7.0/test/test_support.py

                 err += "; run in verbose mode for details"
         raise TestFailed(err)
 
+def filter_maybe(suite):
+    try:
+        i = sys.argv.index('--filter')
+        filter = sys.argv[i+1]
+    except (ValueError, IndexError):
+        return suite
+    tests = []
+    for test in linearize_suite(suite):
+        if filter in test._testMethodName:
+            tests.append(test)
+    return unittest.TestSuite(tests)
+
+def linearize_suite(suite_or_test):
+    try:
+        it = iter(suite_or_test)
+    except TypeError:
+        yield suite_or_test
+        return
+    for subsuite in it:
+        for item in linearize_suite(subsuite):
+            yield item
 
 def run_unittest(*classes):
     """Run tests from unittest.TestCase-derived classes."""
             suite.addTest(cls)
         else:
             suite.addTest(unittest.makeSuite(cls))
+    suite = filter_maybe(suite)
     _run_suite(suite)