Return a list of the DocTests that are defined by the given object's docstring, or by any of its contained objects' docstrings. The optional parameter `module` is the module that contains the given object. If the module is not specified or is None, then
(self, obj, name=None, module=None, globs=None, extraglobs=None)
| 867 | self._exclude_empty = exclude_empty |
| 868 | |
| 869 | def find(self, obj, name=None, module=None, globs=None, extraglobs=None): |
| 870 | """ |
| 871 | Return a list of the DocTests that are defined by the given |
| 872 | object's docstring, or by any of its contained objects' |
| 873 | docstrings. |
| 874 | |
| 875 | The optional parameter `module` is the module that contains |
| 876 | the given object. If the module is not specified or is None, then |
| 877 | the test finder will attempt to automatically determine the |
| 878 | correct module. The object's module is used: |
| 879 | |
| 880 | - As a default namespace, if `globs` is not specified. |
| 881 | - To prevent the DocTestFinder from extracting DocTests |
| 882 | from objects that are imported from other modules. |
| 883 | - To find the name of the file containing the object. |
| 884 | - To help find the line number of the object within its |
| 885 | file. |
| 886 | |
| 887 | Contained objects whose module does not match `module` are ignored. |
| 888 | |
| 889 | If `module` is False, no attempt to find the module will be made. |
| 890 | This is obscure, of use mostly in tests: if `module` is False, or |
| 891 | is None but cannot be found automatically, then all objects are |
| 892 | considered to belong to the (non-existent) module, so all contained |
| 893 | objects will (recursively) be searched for doctests. |
| 894 | |
| 895 | The globals for each DocTest is formed by combining `globs` |
| 896 | and `extraglobs` (bindings in `extraglobs` override bindings |
| 897 | in `globs`). A new copy of the globals dictionary is created |
| 898 | for each DocTest. If `globs` is not specified, then it |
| 899 | defaults to the module's `__dict__`, if specified, or {} |
| 900 | otherwise. If `extraglobs` is not specified, then it defaults |
| 901 | to {}. |
| 902 | |
| 903 | """ |
| 904 | # If name was not specified, then extract it from the object. |
| 905 | if name is None: |
| 906 | name = getattr(obj, '__name__', None) |
| 907 | if name is None: |
| 908 | raise ValueError("DocTestFinder.find: name must be given " |
| 909 | "when obj.__name__ doesn't exist: %r" % |
| 910 | (type(obj),)) |
| 911 | |
| 912 | # Find the module that contains the given object (if obj is |
| 913 | # a module, then module=obj.). Note: this may fail, in which |
| 914 | # case module will be None. |
| 915 | if module is False: |
| 916 | module = None |
| 917 | elif module is None: |
| 918 | module = inspect.getmodule(obj) |
| 919 | |
| 920 | # Read the module's source code. This is used by |
| 921 | # DocTestFinder._find_lineno to find the line number for a |
| 922 | # given object's docstring. |
| 923 | try: |
| 924 | file = inspect.getsourcefile(obj) |
| 925 | except TypeError: |
| 926 | source_lines = None |
no test coverage detected