Using doctests from within unittests
Question: I typically write both unittests and doctests in my modules. I'd like to
automatically run all of my doctests when running the test suite. I think this
is possible, but I'm having a hard time with the syntax.

I have the test suite

    
    
    import unittest
    class ts(unittest.TestCase):
        def test_null(self): self.assertTrue(True)
    if __name__ == '__main__': unittest.main()
    

I'd like to add to this suite all of the doctests in module `module1`. How can
I do this? I've read the [python
docs](http://docs.python.org/library/doctest.html#unittest-api), but I'm not
any closer to success, here. Adding the lines

    
    
    import doctest
    import module1
    suite = doctest.DocTestSuite(module1)
    

doesn't work. `unittest.main()` searches through the current file scope and
runs every test **case** it finds, right? But DocTestSuite produces a test
**suite**. How do I get `unittest.main()` to run the additional cases in the
suite? Or am I just confused and deluded??

Once again, I'd be grateful for any help anyone can offer.


Answer: In this code i combined unittests and doctests from imported module

    
    
    import unittest
    
    
    class ts(unittest.TestCase):
        def test_null(self): self.assertTrue(True)
    class ts1(unittest.TestCase):
        def test_null(self): self.assertTrue(True)
    
    
    
    testSuite = unittest.TestSuite()
    
    testSuite.addTests(unittest.makeSuite(ts))
    testSuite.addTest(unittest.makeSuite(ts1))
    
    import doctest
    import my_module_with_doctests
    
    testSuite.addTest(doctest.DocTestSuite(my_module_with_doctests))
    
    unittest.TextTestRunner(verbosity = 2).run(testSuite)
    

