diff options
authorVincent Driessen <>2010-07-30 16:19:57 +0200
committerVincent Driessen <>2010-07-30 16:19:57 +0200
commitd609b92c15941a3d42cdb7f5cc1390b252ff56e9 (patch)
parent462137e4ddac4303bdb25f84342d7913da8b2011 (diff)
Allow users to extend unittest.TestCase.
When users extend their test cases with custom assert-methods (for example, def assertIsEmail(self, s)), for every test using that assertion, machineout now returns the line number inside the assertIsEmail method. This isn't useful, since you lose the information as to what particular test is failing. This patch solves that problem by skipping any methods that start with 'assert' when walking up the stack trace. And, yes, this assumes the convention that your unittest.TestCase extensions use the 'assert'-prefix, which would be a good naming convention anyway.
1 files changed, 6 insertions, 1 deletions
diff --git a/ b/
index 7609abf..c5144ea 100644
--- a/
+++ b/
@@ -49,7 +49,12 @@ class NoseMachineReadableOutput(Plugin):
49 try: 49 try:
50 while True: 50 while True:
51 fname, lineno, funname, msg = fulltb.pop() 51 fname, lineno, funname, msg = fulltb.pop()
52 if fname.startswith(self.basepath): 52
53 # The check for the `assert' prefix allows the user to extend
54 # unittest.TestCase with custom assert-methods, while
55 # machineout still returns the most useful error line number.
56 if fname.startswith(self.basepath) \
57 and not funname.startswith('assert'):
53 break 58 break
54 except IndexError: 59 except IndexError:
55 fname, lineno, funname, msg = fallback 60 fname, lineno, funname, msg = fallback