Used by discovery. Loads tests from a single file, or a directories' __init__.py when passed the directory. Returns a tuple (None_or_tests_from_file, should_recurse).
(self, full_path, pattern, namespace=False)
| 406 | self._loading_packages.discard(name) |
| 407 | |
| 408 | def _find_test_path(self, full_path, pattern, namespace=False): |
| 409 | """Used by discovery. |
| 410 | |
| 411 | Loads tests from a single file, or a directories' __init__.py when |
| 412 | passed the directory. |
| 413 | |
| 414 | Returns a tuple (None_or_tests_from_file, should_recurse). |
| 415 | """ |
| 416 | basename = os.path.basename(full_path) |
| 417 | if os.path.isfile(full_path): |
| 418 | if not VALID_MODULE_NAME.match(basename): |
| 419 | # valid Python identifiers only |
| 420 | return None, False |
| 421 | if not self._match_path(basename, full_path, pattern): |
| 422 | return None, False |
| 423 | # if the test file matches, load it |
| 424 | name = self._get_name_from_path(full_path) |
| 425 | try: |
| 426 | module = self._get_module_from_name(name) |
| 427 | except case.SkipTest as e: |
| 428 | return _make_skipped_test(name, e, self.suiteClass), False |
| 429 | except: |
| 430 | error_case, error_message = \ |
| 431 | _make_failed_import_test(name, self.suiteClass) |
| 432 | self.errors.append(error_message) |
| 433 | return error_case, False |
| 434 | else: |
| 435 | mod_file = os.path.abspath( |
| 436 | getattr(module, '__file__', full_path)) |
| 437 | realpath = _splitext( |
| 438 | os.path.realpath(mod_file)) |
| 439 | fullpath_noext = _splitext( |
| 440 | os.path.realpath(full_path)) |
| 441 | if realpath.lower() != fullpath_noext.lower(): |
| 442 | module_dir = os.path.dirname(realpath) |
| 443 | mod_name = _splitext( |
| 444 | os.path.basename(full_path)) |
| 445 | expected_dir = os.path.dirname(full_path) |
| 446 | msg = ("%r module incorrectly imported from %r. Expected " |
| 447 | "%r. Is this module globally installed?") |
| 448 | raise ImportError( |
| 449 | msg % (mod_name, module_dir, expected_dir)) |
| 450 | return self.loadTestsFromModule(module, pattern=pattern), False |
| 451 | elif os.path.isdir(full_path): |
| 452 | if (not namespace and |
| 453 | not os.path.isfile(os.path.join(full_path, '__init__.py'))): |
| 454 | return None, False |
| 455 | |
| 456 | load_tests = None |
| 457 | tests = None |
| 458 | name = self._get_name_from_path(full_path) |
| 459 | try: |
| 460 | package = self._get_module_from_name(name) |
| 461 | except case.SkipTest as e: |
| 462 | return _make_skipped_test(name, e, self.suiteClass), False |
| 463 | except: |
| 464 | error_case, error_message = \ |
| 465 | _make_failed_import_test(name, self.suiteClass) |
no test coverage detected