Issue 1681984: unittest documentation is incomplete (original) (raw)
When I tried to write a test suite using many test cases, I read the documentation (docs.python.org) but it does work because I was unable to run my test suite. Using Google I realised that documentation is incomplete! In Python binding of gstreamer, I found a "TextTestRunner"!
So, would it be possible to update the doc?
"Could you please state what exactly is missing from the documentation, in your opinion?"
Well, when I ready Python documentation I expect to have the full list of "builtin" modules, functions and classes. But if you check unittest module, documentation only list TestCase, TestSuite, TestResult and TestLoader. Whereas dir(unittest) gives TestCase, TestLoader, TestProgram, TestResult, TestSuite, TextTestRunner.
So information about TestProgram and TextTestRunner is missing.
I also expect a small example showing how to use a test runner and a test suite.
I'm using: ------------------------------ 8< -----------------------
from unittest import TestSuite, TestLoader, TextTestRunner from sys import exit
def loadTests(loader): """Generator listing all test cases""" ...
def main(): loader = TestLoader()
suite = TestSuite()
for test in loadTests(loader.loadTestsFromTestCase):
suite.addTests(test)
runner = TextTestRunner(descriptions=2, verbosity=2)
result = runner.run(suite)
if result.failures or result.errors:
exit(1)
------------------------------ 8< -----------------------
I don't see the need to document TestProgram or TextTestRunner; the former is an implementation detail of the module (and a messy detail, to boot), not meant to be used in third-party code; the only time you'd come across the latter is when implementing custom test runners, in which case you're to the point of reading the module's source anyway.
As for an example of how to use test runners and test suites, why? "unittest.main()" means most users never need to know about these things. Totally comprehensive documentation is an easy thing to get lost in.