From 35afae1366c57db72189c8348afbb31f297521f6 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Thu, 6 Aug 2009 08:00:23 +1000 Subject: Handle finding a test result when surrounding frames are things like twisted reactors with run methods. --- lib/testresources/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/testresources/__init__.py b/lib/testresources/__init__.py index ccb0109..6da981f 100644 --- a/lib/testresources/__init__.py +++ b/lib/testresources/__init__.py @@ -374,7 +374,12 @@ class ResourcedTestCase(unittest.TestCase): stack = inspect.stack() for frame in stack[3:]: if frame[3] in ('run', '__call__'): - return frame[0].f_locals['result'] + # Not all frames called 'run' will be unittest. It could be a + # reactor in trial, for instance. + result = frame[0].f_locals.get('result') + if (result is not None and + getattr(result, 'startTest', None) is not None): + return result def setUp(self): unittest.TestCase.setUp(self) -- cgit v1.2.1