Skip to content

doctest does not discover tests in joblib-@cache'd functions. #52

@jonovik

Description

@jonovik

doctest does not discover tests in joblib-@cache'd functions. In the output below, note that only 3 of 4 tests get run.

This is with joblib 0.7.0b and python 2.7.2 on Windows 7 64-bit running 32-bit Python.

"""
doctest does not discover tests in joblib-@cache'd functions.

Tests do get discovered in this module docstring:

>>> uncached("module docstring")
'Testing uncached: module docstring'
>>> cached("module docstring")
'Testing cached: module docstring'

However, the doctest in the cached() function below is ignored.
"""

from joblib import Memory
mem = Memory("test-joblib-doctest", verbose=0)

def uncached(x):
    """
    An uncached function.

    >>> uncached("function docstring")
    'Testing uncached: function docstring'
    """
    return "Testing uncached: {}".format(x)

@mem.cache
def cached(x):
    """
    A cached function.

    >>> cached("function docstring")
    'Testing cached: function docstring'
    """
    return "Testing cached: {}".format(x)

if __name__ == "__main__":
    import doctest
    doctest.testmod()

Output:

C:\Users\jonvi>python c:/temp/test_joblib_doctest.py -v
Trying:
    uncached("module docstring")
Expecting:
    'Testing uncached: module docstring'
ok
Trying:
    cached("module docstring")
Expecting:
    'Testing cached: module docstring'
ok
Trying:
    uncached("function docstring")
Expecting:
    'Testing uncached: function docstring'
ok
2 items passed all tests:
   2 tests in __main__
   1 tests in __main__.uncached
3 tests in 2 items.
3 passed and 0 failed.
Test passed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions