(self)
| 593 | self.obj.__pytest_setup_function = xunit_setup_function_fixture |
| 594 | |
| 595 | def _importtestmodule(self): |
| 596 | # We assume we are only called once per module. |
| 597 | importmode = self.config.getoption("--import-mode") |
| 598 | try: |
| 599 | mod = import_path(self.path, mode=importmode, root=self.config.rootpath) |
| 600 | except SyntaxError as e: |
| 601 | raise self.CollectError( |
| 602 | ExceptionInfo.from_current().getrepr(style="short") |
| 603 | ) from e |
| 604 | except ImportPathMismatchError as e: |
| 605 | raise self.CollectError( |
| 606 | "import file mismatch:\n" |
| 607 | "imported module %r has this __file__ attribute:\n" |
| 608 | " %s\n" |
| 609 | "which is not the same as the test file we want to collect:\n" |
| 610 | " %s\n" |
| 611 | "HINT: remove __pycache__ / .pyc files and/or use a " |
| 612 | "unique basename for your test file modules" % e.args |
| 613 | ) from e |
| 614 | except ImportError as e: |
| 615 | exc_info = ExceptionInfo.from_current() |
| 616 | if self.config.getoption("verbose") < 2: |
| 617 | exc_info.traceback = exc_info.traceback.filter(filter_traceback) |
| 618 | exc_repr = ( |
| 619 | exc_info.getrepr(style="short") |
| 620 | if exc_info.traceback |
| 621 | else exc_info.exconly() |
| 622 | ) |
| 623 | formatted_tb = str(exc_repr) |
| 624 | raise self.CollectError( |
| 625 | "ImportError while importing test module '{path}'.\n" |
| 626 | "Hint: make sure your test modules/packages have valid Python names.\n" |
| 627 | "Traceback:\n" |
| 628 | "{traceback}".format(path=self.path, traceback=formatted_tb) |
| 629 | ) from e |
| 630 | except skip.Exception as e: |
| 631 | if e.allow_module_level: |
| 632 | raise |
| 633 | raise self.CollectError( |
| 634 | "Using pytest.skip outside of a test will skip the entire module. " |
| 635 | "If that's your intention, pass `allow_module_level=True`. " |
| 636 | "If you want to skip a specific test or an entire class, " |
| 637 | "use the @pytest.mark.skip or @pytest.mark.skipif decorators." |
| 638 | ) from e |
| 639 | self.config.pluginmanager.consider_module(mod) |
| 640 | return mod |
| 641 | |
| 642 | |
| 643 | class Package(Module): |
no test coverage detected