summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2009-08-06 08:00:23 +1000
committerRobert Collins <robertc@robertcollins.net>2009-08-06 08:00:23 +1000
commit35afae1366c57db72189c8348afbb31f297521f6 (patch)
tree4e385c176c20b2afe570cc79ab2517275bd78533
parent3d38c26794983416ad2acbbe9c3e7ed2e32a5389 (diff)
downloadtestresources-35afae1366c57db72189c8348afbb31f297521f6.tar.gz
Handle finding a test result when surrounding frames are things like twisted reactors with run methods.
-rw-r--r--lib/testresources/__init__.py7
1 files changed, 6 insertions, 1 deletions
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)