I don’t know what’s up, but I ran some old examples, and it looks like doctests aren’t running when I do the “manage.py test” (or the one with a settings file).
I wasn’t able to get it working, at all, but found an interesting semi-workaround… if you don’t have tests in your docstrings, which now seems to be the norm.
from django.test import TestCase
class SimpleTest(TestCase):
def test_x(self):
self.assertEqual(1+1,2)
def test_doctest(self):
import doctest
result = doctest.testfile('doctest.txt', raise_on_error=True)
The interesting stuff is in test_doctest(). It just runs testfile on an extra file. The raise_on_error=True will cause failed tests to register an error in the unit test.
It feels like an ugly hack to me, but I might use it.
This post seems to have a better way to run the doctests. The trick there is DocTestSuite.