aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Cuni <anto.cuni@gmail.com>2011-01-18 16:29:04 +0100
committerAntonio Cuni <anto.cuni@gmail.com>2011-01-18 16:29:04 +0100
commit62ab6227015506896f218c382237373fe69cd945 (patch)
tree707a889094d625f56e561c521111a61fa7778987 /lib-python
parentmake sure that we correctly cache the _ptr of a CFuncPtr. (diff)
parenteven more hackish, add support for --pdb for cpython unittests (diff)
downloadpypy-62ab6227015506896f218c382237373fe69cd945.tar.gz
pypy-62ab6227015506896f218c382237373fe69cd945.tar.bz2
pypy-62ab6227015506896f218c382237373fe69cd945.zip
hg merge default
Diffstat (limited to 'lib-python')
-rw-r--r--lib-python/conftest.py13
-rw-r--r--lib-python/modified-2.7.0/test/test_support.py35
2 files changed, 44 insertions, 4 deletions
diff --git a/lib-python/conftest.py b/lib-python/conftest.py
index ed6bbaa541..00c058afdb 100644
--- a/lib-python/conftest.py
+++ b/lib-python/conftest.py
@@ -36,7 +36,9 @@ def pytest_addoption(parser):
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():
@@ -687,7 +689,14 @@ class ReallyRunFileExternal(py.test.collect.Item):
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.usepdb:
+ cmd += ' --pdb'
+ 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
index f0b270d6c1..d4d138f39e 100644
--- a/lib-python/modified-2.7.0/test/test_support.py
+++ b/lib-python/modified-2.7.0/test/test_support.py
@@ -1052,14 +1052,23 @@ def check_impl_detail(**guards):
guards, default = _parse_guards(guards)
return guards.get(platform.python_implementation().lower(), default)
+class TestResultWithPdb(unittest.result.TestResult):
+ def addError(self, testcase, exc_info):
+ unittest.result.TestResult.addError(self, testcase, exc_info)
+ if '--pdb' in sys.argv:
+ import pdb, traceback
+ traceback.print_tb(exc_info[2])
+ pdb.post_mortem(exc_info[2], pdb.Pdb)
def _run_suite(suite):
"""Run tests from a unittest.TestSuite-derived class."""
if verbose:
- runner = unittest.TextTestRunner(sys.stdout, verbosity=2)
+ runner = unittest.TextTestRunner(sys.stdout, verbosity=2,
+ resultclass=TestResultWithPdb)
else:
- runner = BasicTestRunner()
+ runner = BasicTestRunner(resultclass=TestResultWithPdb)
+
result = runner.run(suite)
if not result.wasSuccessful():
@@ -1073,6 +1082,27 @@ def _run_suite(suite):
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 +1118,7 @@ def run_unittest(*classes):
suite.addTest(cls)
else:
suite.addTest(unittest.makeSuite(cls))
+ suite = filter_maybe(suite)
_run_suite(suite)