Find tests for the given object and any contained objects, and add them to `tests`.
(self, tests, obj, name, module, source_lines, globs, seen)
| 988 | return inspect.isroutine(maybe_routine) |
| 989 | |
| 990 | def _find(self, tests, obj, name, module, source_lines, globs, seen): |
| 991 | """ |
| 992 | Find tests for the given object and any contained objects, and |
| 993 | add them to `tests`. |
| 994 | """ |
| 995 | if self._verbose: |
| 996 | print('Finding tests in %s' % name) |
| 997 | |
| 998 | # If we've already processed this object, then ignore it. |
| 999 | if id(obj) in seen: |
| 1000 | return |
| 1001 | seen[id(obj)] = 1 |
| 1002 | |
| 1003 | # Find a test for this object, and add it to the list of tests. |
| 1004 | test = self._get_test(obj, name, module, globs, source_lines) |
| 1005 | if test is not None: |
| 1006 | tests.append(test) |
| 1007 | |
| 1008 | # Look for tests in a module's contained objects. |
| 1009 | if inspect.ismodule(obj) and self._recurse: |
| 1010 | for valname, val in obj.__dict__.items(): |
| 1011 | valname = '%s.%s' % (name, valname) |
| 1012 | |
| 1013 | # Recurse to functions & classes. |
| 1014 | if ((self._is_routine(val) or inspect.isclass(val)) and |
| 1015 | self._from_module(module, val)): |
| 1016 | self._find(tests, val, valname, module, source_lines, |
| 1017 | globs, seen) |
| 1018 | |
| 1019 | # Look for tests in a module's __test__ dictionary. |
| 1020 | if inspect.ismodule(obj) and self._recurse: |
| 1021 | for valname, val in getattr(obj, '__test__', {}).items(): |
| 1022 | if not isinstance(valname, str): |
| 1023 | raise ValueError("DocTestFinder.find: __test__ keys " |
| 1024 | "must be strings: %r" % |
| 1025 | (type(valname),)) |
| 1026 | if not (inspect.isroutine(val) or inspect.isclass(val) or |
| 1027 | inspect.ismodule(val) or isinstance(val, str)): |
| 1028 | raise ValueError("DocTestFinder.find: __test__ values " |
| 1029 | "must be strings, functions, methods, " |
| 1030 | "classes, or modules: %r" % |
| 1031 | (type(val),)) |
| 1032 | valname = '%s.__test__.%s' % (name, valname) |
| 1033 | self._find(tests, val, valname, module, source_lines, |
| 1034 | globs, seen) |
| 1035 | |
| 1036 | # Look for tests in a class's contained objects. |
| 1037 | if inspect.isclass(obj) and self._recurse: |
| 1038 | for valname, val in obj.__dict__.items(): |
| 1039 | # Special handling for staticmethod/classmethod. |
| 1040 | if isinstance(val, (staticmethod, classmethod)): |
| 1041 | val = val.__func__ |
| 1042 | |
| 1043 | # Recurse to methods, properties, and nested classes. |
| 1044 | if ((inspect.isroutine(val) or inspect.isclass(val) or |
| 1045 | isinstance(val, property)) and |
| 1046 | self._from_module(module, val)): |
| 1047 | valname = '%s.%s' % (name, valname) |
no test coverage detected