Search code examples
nosepython-nose

Run doctest plugin with nose.main


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.


Solution

  • 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.