[pypy-svn] pypy default: even more hackish, add support for --pdb for cpython unittests

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


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r40873:34b33aa04a0c
Date: 2011-01-18 15:22 +0100
http://bitbucket.org/pypy/pypy/changeset/34b33aa04a0c/

Log:	even more hackish, add support for --pdb for cpython unittests

diff --git a/lib-python/conftest.py b/lib-python/conftest.py
--- a/lib-python/conftest.py
+++ b/lib-python/conftest.py
@@ -692,6 +692,8 @@
         else:
             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:

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
@@ -1052,14 +1052,23 @@
     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():


More information about the Pypy-commit mailing list