Skip to content

Commit cee8d6f

Browse files
[7.2.x] Update import mode documentation to not refer to __import__() anymore. (#10751)
Co-authored-by: Manuel Jacob <[email protected]>
1 parent 79108bf commit cee8d6f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

doc/en/explanation/pythonpath.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import process can be controlled through the ``--import-mode`` command-line flag
1616
these values:
1717

1818
* ``prepend`` (default): the directory path containing each module will be inserted into the *beginning*
19-
of :py:data:`sys.path` if not already there, and then imported with the :func:`__import__ <__import__>` builtin.
19+
of :py:data:`sys.path` if not already there, and then imported with the :func:`importlib.import_module <importlib.import_module>` function.
2020

2121
This requires test module names to be unique when the test directory tree is not arranged in
2222
packages, because the modules will put in :py:data:`sys.modules` after importing.
2323

2424
This is the classic mechanism, dating back from the time Python 2 was still supported.
2525

2626
* ``append``: the directory containing each module is appended to the end of :py:data:`sys.path` if not already
27-
there, and imported with ``__import__``.
27+
there, and imported with :func:`importlib.import_module <importlib.import_module>`.
2828

2929
This better allows to run test modules against installed versions of a package even if the
3030
package under test has the same import root. For example:
@@ -43,7 +43,7 @@ these values:
4343
Same as ``prepend``, requires test module names to be unique when the test directory tree is
4444
not arranged in packages, because the modules will put in :py:data:`sys.modules` after importing.
4545

46-
* ``importlib``: new in pytest-6.0, this mode uses :mod:`importlib` to import test modules. This gives full control over the import process, and doesn't require changing :py:data:`sys.path`.
46+
* ``importlib``: new in pytest-6.0, this mode uses more fine control mechanisms provided by :mod:`importlib` to import test modules. This gives full control over the import process, and doesn't require changing :py:data:`sys.path`.
4747

4848
For this reason this doesn't require test module names to be unique.
4949

src/_pytest/pathlib.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,14 @@ def import_path(
464464
465465
* `mode == ImportMode.prepend`: the directory containing the module (or package, taking
466466
`__init__.py` files into account) will be put at the *start* of `sys.path` before
467-
being imported with `__import__.
467+
being imported with `importlib.import_module`.
468468
469469
* `mode == ImportMode.append`: same as `prepend`, but the directory will be appended
470470
to the end of `sys.path`, if not already in `sys.path`.
471471
472472
* `mode == ImportMode.importlib`: uses more fine control mechanisms provided by `importlib`
473-
to import the module, which avoids having to use `__import__` and muck with `sys.path`
474-
at all. It effectively allows having same-named test modules in different places.
473+
to import the module, which avoids having to muck with `sys.path` at all. It effectively
474+
allows having same-named test modules in different places.
475475
476476
:param root:
477477
Used as an anchor when mode == ImportMode.importlib to obtain

0 commit comments

Comments
 (0)