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

Method _find_tests

Lib/unittest/loader.py:373–405  ·  view source on GitHub ↗

Used by discovery. Yields test suites it loads.

(self, start_dir, pattern, namespace=False)

Source from the content-addressed store, hash-verified

371 return fnmatch(path, pattern)
372
373 def _find_tests(self, start_dir, pattern, namespace=False):
374 """Used by discovery. Yields test suites it loads."""
375 # Handle the __init__ in this package
376 name = self._get_name_from_path(start_dir)
377 # name is '.' when start_dir == top_level_dir (and top_level_dir is by
378 # definition not a package).
379 if name != '.' and name not in self._loading_packages:
380 # name is in self._loading_packages while we have called into
381 # loadTestsFromModule with name.
382 tests, should_recurse = self._find_test_path(
383 start_dir, pattern, namespace)
384 if tests is not None:
385 yield tests
386 if not should_recurse:
387 # Either an error occurred, or load_tests was used by the
388 # package.
389 return
390 # Handle the contents.
391 paths = sorted(os.listdir(start_dir))
392 for path in paths:
393 full_path = os.path.join(start_dir, path)
394 tests, should_recurse = self._find_test_path(
395 full_path, pattern, False)
396 if tests is not None:
397 yield tests
398 if should_recurse:
399 # we found a package that didn't use load_tests.
400 name = self._get_name_from_path(full_path)
401 self._loading_packages.add(name)
402 try:
403 yield from self._find_tests(full_path, pattern, False)
404 finally:
405 self._loading_packages.discard(name)
406
407 def _find_test_path(self, full_path, pattern, namespace=False):
408 """Used by discovery.

Calls 7

_get_name_from_pathMethod · 0.95
_find_test_pathMethod · 0.95
sortedFunction · 0.85
listdirMethod · 0.80
joinMethod · 0.45
addMethod · 0.45
discardMethod · 0.45