MCPcopy Index your code
hub / github.com/RustPython/RustPython / discover

Method discover

Lib/unittest/loader.py:228–339  ·  view source on GitHub ↗

Find and return all test modules from the specified start directory, recursing into subdirectories to find them and return all tests found within them. Only test files that match the pattern will be loaded. (Using shell style pattern matching.) All test modules must

(self, start_dir, pattern='test*.py', top_level_dir=None)

Source from the content-addressed store, hash-verified

226 return testFnNames
227
228 def discover(self, start_dir, pattern='test*.py', top_level_dir=None):
229 """Find and return all test modules from the specified start
230 directory, recursing into subdirectories to find them and return all
231 tests found within them. Only test files that match the pattern will
232 be loaded. (Using shell style pattern matching.)
233
234 All test modules must be importable from the top level of the project.
235 If the start directory is not the top level directory then the top
236 level directory must be specified separately.
237
238 If a test package name (directory with '__init__.py') matches the
239 pattern then the package will be checked for a 'load_tests' function. If
240 this exists then it will be called with (loader, tests, pattern) unless
241 the package has already had load_tests called from the same discovery
242 invocation, in which case the package module object is not scanned for
243 tests - this ensures that when a package uses discover to further
244 discover child tests that infinite recursion does not happen.
245
246 If load_tests exists then discovery does *not* recurse into the package,
247 load_tests is responsible for loading all tests in the package.
248
249 The pattern is deliberately not stored as a loader attribute so that
250 packages can continue discovery themselves. top_level_dir is stored so
251 load_tests does not need to pass this argument in to loader.discover().
252
253 Paths are sorted before being imported to ensure reproducible execution
254 order even on filesystems with non-alphabetical ordering like ext3/4.
255 """
256 original_top_level_dir = self._top_level_dir
257 set_implicit_top = False
258 if top_level_dir is None and self._top_level_dir is not None:
259 # make top_level_dir optional if called from load_tests in a package
260 top_level_dir = self._top_level_dir
261 elif top_level_dir is None:
262 set_implicit_top = True
263 top_level_dir = start_dir
264
265 top_level_dir = os.path.abspath(top_level_dir)
266
267 if not top_level_dir in sys.path:
268 # all test modules must be importable from the top level directory
269 # should we *unconditionally* put the start directory in first
270 # in sys.path to minimise likelihood of conflicts between installed
271 # modules and development versions?
272 sys.path.insert(0, top_level_dir)
273 self._top_level_dir = top_level_dir
274
275 is_not_importable = False
276 is_namespace = False
277 tests = []
278 if os.path.isdir(os.path.abspath(start_dir)):
279 start_dir = os.path.abspath(start_dir)
280 if start_dir != top_level_dir:
281 is_not_importable = not os.path.isfile(os.path.join(start_dir, '__init__.py'))
282 else:
283 # support for discovery from dotted module names
284 try:
285 __import__(start_dir)

Calls 14

_find_testsMethod · 0.95
hasattrFunction · 0.85
listClass · 0.85
__import__Function · 0.50
insertMethod · 0.45
isdirMethod · 0.45
isfileMethod · 0.45
joinMethod · 0.45
startswithMethod · 0.45
splitMethod · 0.45
replaceMethod · 0.45