Doctest: Allow checking for intermediate exceptions in traceback

If the error thrown in a doctest command is a ValueError, and that error object has a __context__ of RuntimeError, it would be nice to be able to do this:

>>> function_that_raises()
Traceback (most recent call last):
  ...
RuntimeError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  ...
ValueError

And a similar thing for __cause__ but with the different line of text in the middle.

This doesn’t work right now, I just want to make sure that it’s not an oversight on my end, before I propose this as a feature.

3 Likes

The change would break existing tests, so it would need to be opt-in. For example, you could put it behind a new option flag.

1 Like