This commit is contained in:
Phil Schaf 2024-02-05 16:21:08 +01:00
parent e867798f1a
commit be27caa26c
5 changed files with 7 additions and 1 deletions

View File

@ -309,6 +309,7 @@ Pavel Karateev
Paweł Adamczak
Pedro Algarvio
Petter Strandmark
Philipp A.
Philipp Loose
Pierre Sassoulas
Pieter Mulder

View File

@ -0,0 +1 @@
Fix some instances of importing doctests parent modules when using `--import-mode=importlib`.

View File

@ -173,6 +173,9 @@ ignore = [
[tool.ruff.format]
docstring-code-format = true
[tool.ruff.lint]
allowed-confusables = ["", "×"]
[tool.ruff.lint.pycodestyle]
# In order to be able to format for 88 char in ruff format
max-line-length = 120

View File

@ -617,7 +617,7 @@ def module_name_from_path(path: Path, root: Path) -> str:
_module_name_from_path(path, dir)
for dir in itertools.chain([root], map(Path, sys.path))
)
return ".".join(min(candidates, key=len))
return ".".join(min(candidates, key=len)) # type: ignore[arg-type]
def _module_name_from_path(path: Path, root: Path) -> tuple[str, ...]:

View File

@ -691,6 +691,7 @@ class TestImportLibMode:
init = pkgdir / "__init__.py"
init.write_text("", encoding="ascii")
# the PyTest root is `proj_dir`, but the package is imported from `pkgs_dir`
mod = import_path(init, root=proj_dir, mode=ImportMode.importlib)
# assert that its imported with the canonical name, not “path.to.package.<name>”
mod_names = [n for n, m in sys.modules.items() if m is mod]