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