Welcome to docstringtest documentation!

docstringtest is a small package for regression testing of docstrings in Python code. It checks that all appropriate methods and functions are using ReST docstrings with parameter information so that nice documentation can be generated. This format looks like:

def example_function(varA,varB):
   """
   This function does nothing

   :param varA: The first variable
   :param varB: The second variable
   :type varA: The type of the first variable
   :type varB: The type of the second variable
   """
   pass

It makes it easy to check that the docstrings match with the current parameters so that documentation doesn’t become out-of-step with the code.

If you wanted to add docstringtest to a standard test algorithm, it would simply be something like this

import mymodule
import docstringtest

def test_docstringtest():
        docstringtest.testModule(mymodule)

Testing

These methods will test a module/class or function to check that all functions contain the appropriately formatted docstrings. If not they will raise a DocstringTestError

docstringtest.testModule(m)[source]

Test all the docstrings for classes/functions/methods in a module

Parameters:m (module) – Module to test
docstringtest.testClass(c)[source]

Test all the docstrings for methods in a class

Parameters:c (class) – Class to test
docstringtest.testFunction(func)[source]

Test a function/method to see if the necessary docstring is included. Will check for line describing each parameter and its type. Will also expected at least one line with description of function.

Parameters:func (function/method) – Function/method to test

The Error generated for a failed docstring will be of the following class:

class docstringtest.DocstringTestError(message, filename, funcName)[source]

Special Error for Docstring test failures where an appropriate docstring is not found for a function/method

Generation

These functions help to create docstrings for functions. They will provide strings for skeleton docstrings for an individual function or all the functions in a module/class.

docstringtest.generateDocstring(func)[source]

Generates a skeleton docstring (to be filled in) for a function/method

Parameters:func (function/method) – Function/method that docstring should be generated for
Returns:Skeleton docstring for function/method
Return type:str
docstringtest.generateAllDocstrings(c)[source]

Generate skeleton docstrings for all functions/methods in a module or class

Parameters:c (module/class) – Module or class to generate docstrings for
Returns:All docstrings for functions/methods
Return type:str