| 731 | raise KeyError(name) |
| 732 | |
| 733 | def _importconftest( |
| 734 | self, |
| 735 | conftestpath: pathlib.Path, |
| 736 | importmode: str | ImportMode, |
| 737 | rootpath: pathlib.Path, |
| 738 | *, |
| 739 | consider_namespace_packages: bool, |
| 740 | ) -> types.ModuleType: |
| 741 | conftestpath_plugin_name = str(conftestpath) |
| 742 | existing = self.get_plugin(conftestpath_plugin_name) |
| 743 | if existing is not None: |
| 744 | return cast(types.ModuleType, existing) |
| 745 | |
| 746 | class="cm"># conftest.py files there are not in a Python package all have module |
| 747 | class="cm"># name class="st">"conftest", and thus conflict with each other. Clear the existing |
| 748 | class="cm"># before loading the new one, otherwise the existing one will be |
| 749 | class="cm"># returned from the module cache. |
| 750 | pkgpath = resolve_package_path(conftestpath) |
| 751 | if pkgpath is None: |
| 752 | try: |
| 753 | del sys.modules[conftestpath.stem] |
| 754 | except KeyError: |
| 755 | pass |
| 756 | |
| 757 | try: |
| 758 | mod = import_path( |
| 759 | conftestpath, |
| 760 | mode=importmode, |
| 761 | root=rootpath, |
| 762 | consider_namespace_packages=consider_namespace_packages, |
| 763 | ) |
| 764 | except Exception as e: |
| 765 | assert e.__traceback__ is not None |
| 766 | raise ConftestImportFailure(conftestpath, cause=e) from e |
| 767 | |
| 768 | self._check_non_top_pytest_plugins(mod, conftestpath) |
| 769 | |
| 770 | self._conftest_plugins.add(mod) |
| 771 | dirpath = conftestpath.parent |
| 772 | if dirpath in self._dirpath2confmods: |
| 773 | for path, mods in self._dirpath2confmods.items(): |
| 774 | if dirpath in path.parents or path == dirpath: |
| 775 | if mod in mods: |
| 776 | raise AssertionError( |
| 777 | fclass="st">"While trying to load conftest path {conftestpath!s}, " |
| 778 | fclass="st">"found that the module {mod} is already loaded with path {mod.__file__}. " |
| 779 | class="st">"This is not supposed to happen. Please report this issue to pytest." |
| 780 | ) |
| 781 | mods.append(mod) |
| 782 | self.trace(fclass="st">"loading conftestmodule {mod!r}") |
| 783 | self.consider_conftest(mod, registration_name=conftestpath_plugin_name) |
| 784 | return mod |
| 785 | |
| 786 | def _check_non_top_pytest_plugins( |
| 787 | self, |