Merge lp:~anybox/openerp-command/trunk-pdb-tests-poc into lp:openerp-command

Proposed by Georges Racinet
Status: Needs review
Proposed branch: lp:~anybox/openerp-command/trunk-pdb-tests-poc
Merge into: lp:openerp-command
Diff against target: 59 lines (+31/-1)
2 files modified
openerpcommand/run_tests.py (+11/-1)
openerpcommand/test_result.py (+20/-0)
To merge this branch: bzr merge lp:~anybox/openerp-command/trunk-pdb-tests-poc
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+132801@code.launchpad.net

Description of the change

This is a proof-of-concept implementation of post-mortem pdb for failures and errors.

The pdb related options are directly set on the TestResult subclass, which is a bit harsh and could be surprising for further developments, but that's good enough to demonstrate that it works.

A cleaner way would be to subclass TextTestRunner as well to pass options to PdbTextTestResult.__init__(). That kind of subclassing would not lead to much duplication.

If you'd prefer it that way, just tell me.

Cheers,

To post a comment you must log in.
Revision history for this message
Vo Minh Thu (thu) wrote :

This seems nice (I didn't try it).

Actually in the case of a failure, the stack wouldn't be much interesting (the stack would lead to the assertion error, not to the code at fault).

So this makes it possible to write it a bit more cleanly: just check a single --post-mortem flag, if it true, use your PdbTextTestResult, otherwise use the regular TextTestResult. (So no need to pass aroung the flag through class variables.)

Thanks!

Revision history for this message
Vo Minh Thu (thu) wrote :

(I mean, the `if flag` in the PdbTextTestResult can be removed as the class is used only when the only remaining flag is True.)

Unmerged revisions

182. By Georges Racinet <email address hidden>

[IMP] options for pdb post-mortem debugging on failures and errors

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerpcommand/run_tests.py'
2--- openerpcommand/run_tests.py 2012-10-09 12:34:39 +0000
3+++ openerpcommand/run_tests.py 2012-11-04 12:26:19 +0000
4@@ -91,6 +91,7 @@
5
6 def run(args):
7 import unittest2
8+ from .test_result import PdbTextTestResult
9
10 import openerp
11
12@@ -157,7 +158,10 @@
13 suite = unittest2.TestSuite()
14 for test_module in test_modules:
15 suite.addTests(unittest2.TestLoader().loadTestsFromModule(test_module))
16- unittest2.TextTestRunner(verbosity=2).run(suite)
17+ PdbTextTestResult.pdb_errors = bool(args.pdb)
18+ PdbTextTestResult.pdb_failures = bool(args.pdb_failures)
19+ unittest2.TextTestRunner(resultclass=PdbTextTestResult,
20+ verbosity=2).run(suite)
21 else:
22 print 'Test modules:'
23 for test_module in test_modules:
24@@ -187,4 +191,10 @@
25 parser.add_argument('--dry-run', action='store_true',
26 help='do not run the tests')
27
28+ # options for post-mortem pdb, named as in nosetests
29+ parser.add_argument('--pdb', action='store_true',
30+ help='Invoke post mortem pdb on errors')
31+ parser.add_argument('--pdb-failures', action='store_true',
32+ help='Invoke post mortem pdb on failures')
33+
34 parser.set_defaults(run=run)
35
36=== added file 'openerpcommand/test_result.py'
37--- openerpcommand/test_result.py 1970-01-01 00:00:00 +0000
38+++ openerpcommand/test_result.py 2012-11-04 12:26:19 +0000
39@@ -0,0 +1,20 @@
40+import pdb
41+from unittest2.runner import TextTestResult
42+
43+class PdbTextTestResult(TextTestResult):
44+ """A subclass with post-mortem pdb capability for errors and failures.
45+ """
46+
47+ pdb_failures = False
48+
49+ pdb_errors = False
50+
51+ def addFailure(self, test, err):
52+ super(PdbTextTestResult, self).addFailure(test, err)
53+ if self.pdb_failures:
54+ pdb.post_mortem(err[2])
55+
56+ def addError(self, test, err):
57+ super(PdbTextTestResult, self).addError(test, err)
58+ if self.pdb_errors:
59+ pdb.post_mortem(err[2])

Subscribers

People subscribed via source and target branches