Find tests for the given object and any contained objects, and add them to `tests`.
(self, tests, obj, name, module, source_lines, globs, seen)
| 1009 | return inspect.isroutine(maybe_routine) |
| 1010 | |
| 1011 | def _find(self, tests, obj, name, module, source_lines, globs, seen): |
| 1012 | """ |
| 1013 | Find tests for the given object and any contained objects, and |
| 1014 | add them to `tests`. |
| 1015 | """ |
| 1016 | if self._verbose: |
| 1017 | print('Finding tests in %s' % name) |
| 1018 | |
| 1019 | # If we've already processed this object, then ignore it. |
| 1020 | if id(obj) in seen: |
| 1021 | return |
| 1022 | seen[id(obj)] = 1 |
| 1023 | |
| 1024 | # Find a test for this object, and add it to the list of tests. |
| 1025 | test = self._get_test(obj, name, module, globs, source_lines) |
| 1026 | if test is not None: |
| 1027 | tests.append(test) |
| 1028 | |
| 1029 | # Look for tests in a module's contained objects. |
| 1030 | if inspect.ismodule(obj) and self._recurse: |
| 1031 | for valname, val in obj.__dict__.items(): |
| 1032 | valname = '%s.%s' % (name, valname) |
| 1033 | |
| 1034 | # Recurse to functions & classes. |
| 1035 | if ((self._is_routine(val) or inspect.isclass(val)) and |
| 1036 | self._from_module(module, val)): |
| 1037 | self._find(tests, val, valname, module, source_lines, |
| 1038 | globs, seen) |
| 1039 | |
| 1040 | # Look for tests in a module's __test__ dictionary. |
| 1041 | if inspect.ismodule(obj) and self._recurse: |
| 1042 | for valname, val in getattr(obj, '__test__', {}).items(): |
| 1043 | if not isinstance(valname, str): |
| 1044 | raise ValueError("DocTestFinder.find: __test__ keys " |
| 1045 | "must be strings: %r" % |
| 1046 | (type(valname),)) |
| 1047 | if not (inspect.isroutine(val) or inspect.isclass(val) or |
| 1048 | inspect.ismodule(val) or isinstance(val, str)): |
| 1049 | raise ValueError("DocTestFinder.find: __test__ values " |
| 1050 | "must be strings, functions, methods, " |
| 1051 | "classes, or modules: %r" % |
| 1052 | (type(val),)) |
| 1053 | valname = '%s.__test__.%s' % (name, valname) |
| 1054 | self._find(tests, val, valname, module, source_lines, |
| 1055 | globs, seen) |
| 1056 | |
| 1057 | # Look for tests in a class's contained objects. |
| 1058 | if inspect.isclass(obj) and self._recurse: |
| 1059 | for valname, val in obj.__dict__.items(): |
| 1060 | # Special handling for staticmethod/classmethod. |
| 1061 | if isinstance(val, (staticmethod, classmethod)): |
| 1062 | val = val.__func__ |
| 1063 | |
| 1064 | # Recurse to methods, properties, and nested classes. |
| 1065 | if ((inspect.isroutine(val) or inspect.isclass(val) or |
| 1066 | isinstance(val, property)) and |
| 1067 | self._from_module(module, val)): |
| 1068 | valname = '%s.%s' % (name, valname) |
no test coverage detected