Lines Matching +full:module +full:- +full:path +full:- +full:tests
17 # we would need to avoid loading the same tests multiple times
19 VALID_MODULE_NAME = re.compile(r'[_a-z]\w*\.py$', re.IGNORECASE)
23 message = 'Failed to import test module: %s\n%s' % (name, traceback.format_exc())
40 This class is responsible for loading tests according to various criteria
59 def loadTestsFromModule(self, module, use_load_tests=True): argument
60 """Return a suite of all test cases contained in the given module"""
61 tests = []
62 for name in dir(module):
63 obj = getattr(module, name)
65 tests.append(self.loadTestsFromTestCase(obj))
67 load_tests = getattr(module, 'load_tests', None)
68 tests = self.suiteClass(tests)
71 return load_tests(self, tests, None)
73 return _make_failed_load_tests(module.__name__, e,
75 return tests
77 def loadTestsFromName(self, name, module=None): argument
80 The name may resolve either to a module, a test case class, a
84 The method optionally resolves the names relative to a given module.
87 if module is None:
91 module = __import__('.'.join(parts_copy))
94 del parts_copy[-1]
98 obj = module
109 name = parts[-1]
126 def loadTestsFromNames(self, names, module=None): argument
130 suites = [self.loadTestsFromName(name, module) for name in names]
157 this exists then it will be called with loader, tests, pattern.
160 load_tests is responsible for loading all tests in the package.
174 top_level_dir = os.path.abspath(top_level_dir)
176 if not top_level_dir in sys.path:
179 # in sys.path to minimise likelihood of conflicts between installed
181 sys.path.insert(0, top_level_dir)
185 if os.path.isdir(os.path.abspath(start_dir)):
186 start_dir = os.path.abspath(start_dir)
188 is_not_importable = not os.path.isfile(os.path.join(start_dir, '__init__.py'))
190 # support for discovery from dotted module names
198 start_dir = os.path.abspath(os.path.dirname((the_module.__file__)))
201 sys.path.remove(top_level_dir)
206 tests = list(self._find_tests(start_dir, pattern))
207 return self.suiteClass(tests)
210 module = sys.modules[module_name]
211 full_path = os.path.abspath(module.__file__)
213 if os.path.basename(full_path).lower().startswith('__init__.py'):
214 return os.path.dirname(os.path.dirname(full_path))
216 # here we have been given a module rather than a package - so
217 # all we can do is search the *same* directory the module is in
219 return os.path.dirname(full_path)
221 def _get_name_from_path(self, path): argument
222 path = os.path.splitext(os.path.normpath(path))[0]
224 _relpath = os.path.relpath(path, self._top_level_dir)
225 assert not os.path.isabs(_relpath), "Path must be within the project"
226 assert not _relpath.startswith('..'), "Path must be within the project"
228 name = _relpath.replace(os.path.sep, '.')
235 def _match_path(self, path, full_path, pattern): argument
237 return fnmatch(path, pattern)
243 for path in paths:
244 full_path = os.path.join(start_dir, path)
245 if os.path.isfile(full_path):
246 if not VALID_MODULE_NAME.match(path):
249 if not self._match_path(path, full_path, pattern):
254 module = self._get_module_from_name(name)
258 mod_file = os.path.abspath(getattr(module, '__file__', full_path))
259 realpath = os.path.splitext(os.path.realpath(mod_file))[0]
260 fullpath_noext = os.path.splitext(os.path.realpath(full_path))[0]
262 module_dir = os.path.dirname(realpath)
263 mod_name = os.path.splitext(os.path.basename(full_path))[0]
264 expected_dir = os.path.dirname(full_path)
265 msg = ("%r module incorrectly imported from %r. Expected %r. "
266 "Is this module globally installed?")
268 yield self.loadTestsFromModule(module)
269 elif os.path.isdir(full_path):
270 if not os.path.isfile(os.path.join(full_path, '__init__.py')):
274 tests = None
275 if fnmatch(path, pattern):
280 tests = self.loadTestsFromModule(package, use_load_tests=False)
283 if tests is not None:
284 # tests loaded from package file
285 yield tests
291 yield load_tests(self, tests, pattern)
314 def findTestCases(module, prefix='test', sortUsing=cmp, argument
316 return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromModule(module)