diff options
author | Robert Collins <robertc@robertcollins.net> | 2009-08-06 08:00:23 +1000 |
---|---|---|
committer | Robert Collins <robertc@robertcollins.net> | 2009-08-06 08:00:23 +1000 |
commit | 35afae1366c57db72189c8348afbb31f297521f6 (patch) | |
tree | 4e385c176c20b2afe570cc79ab2517275bd78533 | |
parent | 3d38c26794983416ad2acbbe9c3e7ed2e32a5389 (diff) | |
download | testresources-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__.py | 7 |
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) |