@@ -48,10 +48,10 @@ def _test():
4848+ M.__doc__.
4949
5050+ f.__doc__ for all functions f in M.__dict__.values(), except those
51- with private names and those defined in other modules.
51+ defined in other modules.
5252
53- + C.__doc__ for all classes C in M.__dict__.values(), except those with
54- private names and those defined in other modules.
53+ + C.__doc__ for all classes C in M.__dict__.values(), except those
54+ defined in other modules.
5555
5656+ If M.__test__ exists and "is true", it must be a dict, and
5757 each entry maps a (string) name to a function object, class object, or
@@ -62,13 +62,16 @@ def _test():
6262 <name of M>.__test__.K
6363
6464Any classes found are recursively searched similarly, to test docstrings in
65- their contained methods and nested classes. Private names reached from M's
66- globals are skipped, but all names reached from M.__test__ are searched.
65+ their contained methods and nested classes. All names reached from
66+ M.__test__ are searched.
6767
68- By default, a name is considered to be private if it begins with an
69- underscore (like "_my_func") but doesn't both begin and end with (at least)
70- two underscores (like "__init__"). You can change the default by passing
71- your own "isprivate" function to testmod.
68+ Optionally, functions with private names can be skipped (unless listed in
69+ M.__test__) by supplying a function to the "isprivate" argument that will
70+ identify private functions. For convenience, one such function is
71+ supplied. docttest.is_private considers a name to be private if it begins
72+ with an underscore (like "_my_func") but doesn't both begin and end with
73+ (at least) two underscores (like "__init__"). By supplying this function
74+ or your own "isprivate" function to testmod, the behavior can be customized.
7275
7376If you want to test docstrings in objects with private names too, stuff
7477them into an M.__test__ dict, or see ADVANCED USAGE below (e.g., pass your
@@ -671,8 +674,10 @@ def __init__(self, mod=None, globs=None, verbose=None,
671674failures if false; by default, it's true iff "-v" is in sys.argv.
672675
673676Optional keyword arg "isprivate" specifies a function used to determine
674- whether a name is private. The default function is doctest.is_private;
675- see its docs for details.
677+ whether a name is private. The default function is to assume that
678+ no functions are private. The "isprivate" arg may be set to
679+ doctest.is_private in order to skip over functions marked as private
680+ using an underscore naming convention; see its docs for details.
676681
677682See doctest.testmod docs for the meaning of optionflags.
678683"""
@@ -691,8 +696,9 @@ def __init__(self, mod=None, globs=None, verbose=None,
691696 verbose = "-v" in sys .argv
692697 self .verbose = verbose
693698
699+ # By default, assume that nothing is private
694700 if isprivate is None :
695- isprivate = is_private
701+ isprivate = lambda prefix , base : 0
696702 self .isprivate = isprivate
697703
698704 self .optionflags = optionflags
@@ -861,26 +867,26 @@ def rundict(self, d, name, module=None):
861867
862868 Tests that objects outside m1 are excluded:
863869
864- >>> t = Tester(globs={}, verbose=0)
870+ >>> t = Tester(globs={}, verbose=0, isprivate=is_private )
865871 >>> t.rundict(m1.__dict__, "rundict_test", m1) # _f, f2 and g2 and h2 skipped
866872 (0, 3)
867873
868- Again, but with a custom isprivate function allowing _f:
874+ Again, but with the default isprivate function allowing _f:
869875
870- >>> t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0 )
876+ >>> t = Tester(globs={}, verbose=0)
871877 >>> t.rundict(m1.__dict__, "rundict_test_pvt", m1) # Only f2, g2 and h2 skipped
872878 (0, 4)
873879
874880 And once more, not excluding stuff outside m1:
875881
876- >>> t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0 )
882+ >>> t = Tester(globs={}, verbose=0)
877883 >>> t.rundict(m1.__dict__, "rundict_test_pvt") # None are skipped.
878884 (0, 8)
879885
880886 The exclusion of objects from outside the designated module is
881887 meant to be invoked automagically by testmod.
882888
883- >>> testmod(m1)
889+ >>> testmod(m1, isprivate=is_private )
884890 (0, 3)
885891
886892 """
@@ -1070,7 +1076,8 @@ def testmod(m=None, name=None, globs=None, verbose=None, isprivate=None,
10701076
10711077 Test examples in docstrings in functions and classes reachable
10721078 from module m (or the current module if m is not supplied), starting
1073- with m.__doc__. Private names are skipped.
1079+ with m.__doc__. Unless isprivate is specified, private names
1080+ are not skipped.
10741081
10751082 Also test examples reachable from dict m.__test__ if it exists and is
10761083 not None. m.__dict__ maps names to functions, classes and strings;
@@ -1094,7 +1101,9 @@ def testmod(m=None, name=None, globs=None, verbose=None, isprivate=None,
10941101
10951102 Optional keyword arg "isprivate" specifies a function used to
10961103 determine whether a name is private. The default function is
1097- doctest.is_private; see its docs for details.
1104+ treat all functions as public. Optionally, "isprivate" can be
1105+ set to doctest.is_private to skip over functions marked as private
1106+ using the underscore naming convention; see its docs for details.
10981107
10991108 Optional keyword arg "report" prints a summary at the end when true,
11001109 else prints nothing at the end. In verbose mode, the summary is
0 commit comments