summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Driessen <vincent@datafox.nl>2010-07-30 16:19:57 +0200
committerVincent Driessen <vincent@datafox.nl>2010-07-30 16:19:57 +0200
commitd609b92c15941a3d42cdb7f5cc1390b252ff56e9 (patch)
tree4c2ce03aaaa4fdab1b7b538a64e21a596bb157c6
parent462137e4ddac4303bdb25f84342d7913da8b2011 (diff)
downloadnose-machineout-d609b92c15941a3d42cdb7f5cc1390b252ff56e9.tar.bz2
nose-machineout-d609b92c15941a3d42cdb7f5cc1390b252ff56e9.tar.xz
nose-machineout-d609b92c15941a3d42cdb7f5cc1390b252ff56e9.zip
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.
-rw-r--r--machineout.py7
1 files changed, 6 insertions, 1 deletions
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):
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