1

Following these posts, I have managed to run my doctest within django with:

# myapp/tests.py

import doctest
def load_tests(loader, tests, ignore):
    tests.addTests(doctest.DocTestSuite())
    return tests

Then running:

python manage.py tests

However, since I am used to test my (non-django) scripts with the simple command:

py.test --doctest-modules -x

I am now quite confused about:

  • testing procedure not stopping after first failure (my good'ol -x) (so I get flooded with results and I need to scroll back all the way up to the first problem each time)
  • option # doctest: +ELLIPSIS not being set by default.

How do I set this kind of options from this django load_tests() hook?

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
iago-lito
  • 3,098
  • 3
  • 29
  • 54

1 Answers1

1

Okay, I've got it. Options flags like ELLIPSIS or FAIL_FAST can be provided as an optionflags argument to DocTestSuite.

The right way to combine them, as reported here, is to bitwise OR them :)

So the following does work:

# myapp/tests.py

import doctest
def load_tests(loader, tests, ignore):
    tests.addTests(doctest.DocTestSuite(
                optionflags=doctest.ELLIPSIS | doctest.FAIL_FAST))
    return tests
iago-lito
  • 3,098
  • 3
  • 29
  • 54