(
path: Path,
config: Config,
)
| 499 | |
| 500 | |
| 501 | def importtestmodule( |
| 502 | path: Path, |
| 503 | config: Config, |
| 504 | ): |
| 505 | class="cm"># We assume we are only called once per module. |
| 506 | importmode = config.getoption(class="st">"--import-mode") |
| 507 | try: |
| 508 | mod = import_path( |
| 509 | path, |
| 510 | mode=importmode, |
| 511 | root=config.rootpath, |
| 512 | consider_namespace_packages=config.getini(class="st">"consider_namespace_packages"), |
| 513 | ) |
| 514 | except SyntaxError as e: |
| 515 | raise nodes.Collector.CollectError( |
| 516 | ExceptionInfo.from_current().getrepr(style=class="st">"short") |
| 517 | ) from e |
| 518 | except ImportPathMismatchError as e: |
| 519 | raise nodes.Collector.CollectError( |
| 520 | class="st">"import file mismatch:\n" |
| 521 | class="st">"imported module {!r} has this __file__ attribute:\n" |
| 522 | class="st">" {}\n" |
| 523 | class="st">"which is not the same as the test file we want to collect:\n" |
| 524 | class="st">" {}\n" |
| 525 | class="st">"HINT: remove __pycache__ / .pyc files and/or use a " |
| 526 | class="st">"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=class="st">"short") |
| 534 | if exc_info.traceback |
| 535 | else exc_info.exconly() |
| 536 | ) |
| 537 | formatted_tb = str(exc_repr) |
| 538 | raise nodes.Collector.CollectError( |
| 539 | fclass="st">"ImportError while importing test module &class="cm">#x27;{path}'.\n" |
| 540 | class="st">"Hint: make sure your test modules/packages have valid Python names.\n" |
| 541 | class="st">"Traceback:\n" |
| 542 | fclass="st">"{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 | class="st">"Using pytest.skip outside of a test will skip the entire module. " |
| 549 | class="st">"If that&class="cm">#x27;s your intention, pass `allow_module_level=True`. " |
| 550 | class="st">"If you want to skip a specific test or an entire class, " |
| 551 | class="st">"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