Skip to content

Commit 199d4e2

Browse files
committed
pathlib: import signature and docs for import_path
1 parent 5746b8e commit 199d4e2

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/_pytest/pathlib.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -484,26 +484,31 @@ class ImportPathMismatchError(ImportError):
484484

485485

486486
def import_path(
487-
p: Union[str, "os.PathLike[str]"],
487+
path: Union[str, "os.PathLike[str]"],
488488
*,
489489
mode: Union[str, ImportMode] = ImportMode.prepend,
490490
root: Path,
491491
) -> ModuleType:
492-
"""Import and return a module from the given path, which can be a file (a module) or
492+
"""
493+
Import and return a module from the given path, which can be a file (a module) or
493494
a directory (a package).
494495
495-
The import mechanism used is controlled by the `mode` parameter:
496+
:param path:
497+
Path to the file to import.
496498
497-
* `mode == ImportMode.prepend`: the directory containing the module (or package, taking
498-
`__init__.py` files into account) will be put at the *start* of `sys.path` before
499-
being imported with `importlib.import_module`.
499+
:param mode:
500+
Controls the underlying import mechanism that will be used:
500501
501-
* `mode == ImportMode.append`: same as `prepend`, but the directory will be appended
502-
to the end of `sys.path`, if not already in `sys.path`.
502+
* ImportMode.prepend: the directory containing the module (or package, taking
503+
`__init__.py` files into account) will be put at the *start* of `sys.path` before
504+
being imported with `importlib.import_module`.
503505
504-
* `mode == ImportMode.importlib`: uses more fine control mechanisms provided by `importlib`
505-
to import the module, which avoids having to muck with `sys.path` at all. It effectively
506-
allows having same-named test modules in different places.
506+
* ImportMode.append: same as `prepend`, but the directory will be appended
507+
to the end of `sys.path`, if not already in `sys.path`.
508+
509+
* ImportMode.importlib: uses more fine control mechanisms provided by `importlib`
510+
to import the module, which avoids having to muck with `sys.path` at all. It effectively
511+
allows having same-named test modules in different places.
507512
508513
:param root:
509514
Used as an anchor when mode == ImportMode.importlib to obtain
@@ -514,10 +519,9 @@ def import_path(
514519
If after importing the given `path` and the module `__file__`
515520
are different. Only raised in `prepend` and `append` modes.
516521
"""
522+
path = Path(path)
517523
mode = ImportMode(mode)
518524

519-
path = Path(p)
520-
521525
if not path.exists():
522526
raise ImportError(path)
523527

0 commit comments

Comments
 (0)