| 286 | super(DocTestCase, self).setUp() |
| 287 | |
| 288 | def tearDown(self): |
| 289 | |
| 290 | # Undo the test.globs reassignment we made, so that the parent class |
| 291 | # teardown doesn't destroy the ipython namespace |
| 292 | if isinstance(self._dt_test.examples[0], IPExample): |
| 293 | self._dt_test.globs = self._dt_test_globs_ori |
| 294 | _ip.user_ns.clear() |
| 295 | _ip.user_ns.update(self.user_ns_orig) |
| 296 | |
| 297 | # XXX - fperez: I am not sure if this is truly a bug in nose 0.11, but |
| 298 | # it does look like one to me: its tearDown method tries to run |
| 299 | # |
| 300 | # delattr(builtin_mod, self._result_var) |
| 301 | # |
| 302 | # without checking that the attribute really is there; it implicitly |
| 303 | # assumes it should have been set via displayhook. But if the |
| 304 | # displayhook was never called, this doesn't necessarily happen. I |
| 305 | # haven't been able to find a little self-contained example outside of |
| 306 | # ipython that would show the problem so I can report it to the nose |
| 307 | # team, but it does happen a lot in our code. |
| 308 | # |
| 309 | # So here, we just protect as narrowly as possible by trapping an |
| 310 | # attribute error whose message would be the name of self._result_var, |
| 311 | # and letting any other error propagate. |
| 312 | try: |
| 313 | super(DocTestCase, self).tearDown() |
| 314 | except AttributeError as exc: |
| 315 | if exc.args[0] != self._result_var: |
| 316 | raise |
| 317 | |
| 318 | |
| 319 | # A simple subclassing of the original with a different class name, so we can |