From d609b92c15941a3d42cdb7f5cc1390b252ff56e9 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Fri, 30 Jul 2010 16:19:57 +0200 Subject: 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. --- machineout.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/machineout.py b/machineout.py index 7609abf..c5144ea 100644 --- a/machineout.py +++ b/machineout.py @@ -49,7 +49,12 @@ class NoseMachineReadableOutput(Plugin): try: while True: fname, lineno, funname, msg = fulltb.pop() - if fname.startswith(self.basepath): + + # The check for the `assert' prefix allows the user to extend + # unittest.TestCase with custom assert-methods, while + # machineout still returns the most useful error line number. + if fname.startswith(self.basepath) \ + and not funname.startswith('assert'): break except IndexError: fname, lineno, funname, msg = fallback -- cgit v1.2.3