(
path: Path,
config: Config,
)
| 499 | |
| 500 | |
| 501 | def importtestmodule( |
| 502 | path: Path, |
| 503 | config: Config, |
| 504 | ): |
| 505 | # We assume we are only called once per module. |
| 506 | importmode = config.getoption("--import-mode") |
| 507 | try: |
| 508 | mod = import_path( |
| 509 | path, |
| 510 | mode=importmode, |
| 511 | root=config.rootpath, |
| 512 | consider_namespace_packages=config.getini("consider_namespace_packages"), |
| 513 | ) |
| 514 | except SyntaxError as e: |
| 515 | raise nodes.Collector.CollectError( |
| 516 | ExceptionInfo.from_current().getrepr(style="short") |
| 517 | ) from e |
| 518 | except ImportPathMismatchError as e: |
| 519 | raise nodes.Collector.CollectError( |
| 520 | "import file mismatch:\n" |
| 521 | "imported module {!r} has this __file__ attribute:\n" |
| 522 | " {}\n" |
| 523 | "which is not the same as the test file we want to collect:\n" |
| 524 | " {}\n" |
| 525 | "HINT: remove __pycache__ / .pyc files and/or use a " |
| 526 | "unique basename for your test file modules".format(*e.args) |
| 527 | ) from e |
| 528 | except ImportError as e: |
| 529 | exc_info = ExceptionInfo.from_current() |
| 530 | if config.get_verbosity() < 2: |
| 531 | exc_info.traceback = exc_info.traceback.filter(filter_traceback) |
| 532 | exc_repr = ( |
| 533 | exc_info.getrepr(style="short") |
| 534 | if exc_info.traceback |
| 535 | else exc_info.exconly() |
| 536 | ) |
| 537 | formatted_tb = str(exc_repr) |
| 538 | raise nodes.Collector.CollectError( |
| 539 | f"ImportError while importing test module '{path}'.\n" |
| 540 | "Hint: make sure your test modules/packages have valid Python names.\n" |
| 541 | "Traceback:\n" |
| 542 | f"{formatted_tb}" |
| 543 | ) from e |
| 544 | except skip.Exception as e: |
| 545 | if e.allow_module_level: |
| 546 | raise |
| 547 | raise nodes.Collector.CollectError( |
| 548 | "Using pytest.skip outside of a test will skip the entire module. " |
| 549 | "If that's your intention, pass `allow_module_level=True`. " |
| 550 | "If you want to skip a specific test or an entire class, " |
| 551 | "use the @pytest.mark.skip or @pytest.mark.skipif decorators." |
| 552 | ) from e |
| 553 | config.pluginmanager.consider_module(mod) |
| 554 | return mod |
| 555 | |
| 556 | |
| 557 | class Module(nodes.File, PyCollector): |
no test coverage detected
searching dependent graphs…