<p>Is it possible to write a <code>doctest</code> unit test that will check that an exception is raised?<br />
For example, if I have a function <code>foo(x)</code> that is supposed to raise an exception if <code>x &lt; 0</code>, how would I write the <code>doctest</code> for that?</p>

Yes. You can do it. The
doctest module documentation
and Wikipedia has an
example
of it.
```
```
>>> x
   Traceback (most recent call last):
     ...
   NameError: name 'x' is not defined
```
```