[pypy-svn] pypy default: a bit hackish, but add a --filter option to py.test which works similarly to -k, but filters the cpython unittest

antocuni commits-noreply at bitbucket.org
Tue Jan 18 16:35:18 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r40872:9ec4ff582b3c
Date: 2011-01-18 15:08 +0100
http://bitbucket.org/pypy/pypy/changeset/9ec4ff582b3c/

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

diff --git a/lib-python/conftest.py b/lib-python/conftest.py
--- a/lib-python/conftest.py
+++ b/lib-python/conftest.py
@@ -36,7 +36,9 @@
     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(): 
@@ -688,7 +690,12 @@
             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:

diff --git a/lib-python/modified-2.7.0/test/test_support.py b/lib-python/modified-2.7.0/test/test_support.py
--- a/lib-python/modified-2.7.0/test/test_support.py
+++ b/lib-python/modified-2.7.0/test/test_support.py
@@ -1073,6 +1073,27 @@
                 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."""
@@ -1088,6 +1109,7 @@
             suite.addTest(cls)
         else:
             suite.addTest(unittest.makeSuite(cls))
+    suite = filter_maybe(suite)
     _run_suite(suite)
 
 


More information about the Pypy-commit mailing list