2

I would like to run the Nose builtin Doctest plugin from within Python, notably without command line options or environment variables.

One would expect the following to work:

import nose, os
from nose.plugins.builtin import Doctest
# or from nose.plugins.doctests import Doctest

plugins = [Doctest(),]

nose.main(addplugins=plugins)
# or nose.main(plugins=plugins)

However the above does not seem to load the Doctest plugin as expected.

Thoughts and input would be appreciated.

Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343

2 Answers2

2

Here is what I did:

import nose

argv = sys.argv[:]
argv.insert(1, "--with-doctest")

nose.main(argv=argv)

It isn't as clean as I would like, but it works.

Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
1

Based on Brian's solution, one can also, in order to launch everything from an interactive session, do the following:

import nose
nose.run(argv=['', '--with-doctest'])  # first empty item is ignored by nose.run

But your solution is better for a script that would be launched directly from a command-line, possibly with additional options.

Joël
  • 2,723
  • 18
  • 36