@@ -88,14 +88,6 @@ This has the following benefits:
8888
8989* Your tests can run against an installed version after executing ``pip install . ``.
9090* Your tests can run against the local copy with an editable install after executing ``pip install --editable . ``.
91- * If you don't use an editable install and are relying on the fact that Python by default puts the current
92- directory in ``sys.path `` to import your package, you can execute ``python -m pytest `` to execute the tests against the
93- local copy directly, without using ``pip ``.
94-
95- .. note ::
96-
97- See :ref: `pytest vs python -m pytest ` for more information about the difference between calling ``pytest `` and
98- ``python -m pytest ``.
9991
10092For new projects, we recommend to use ``importlib `` :ref: `import mode <import-modes >`
10193(see which-import-mode _ for a detailed explanation).
@@ -120,6 +112,32 @@ which are better explained in this excellent `blog post`_ by Ionel Cristian Măr
120112
121113.. _blog post : https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-structure>
122114
115+ .. note ::
116+
117+ If you do not use an editable install and use the ``src `` layout as above you need to extend the Python's
118+ search path for module files to execute the tests against the local copy directly. You can do it in an
119+ ad-hoc manner by setting the ``PYTHONPATH `` environment variable:
120+
121+ .. code-block :: bash
122+
123+ PYTHONPATH=src pytest
124+
125+ or in a permanent manner by using the :confval: `pythonpath ` configuration variable and adding the
126+ following to your ``pyproject.toml ``:
127+
128+ .. code-block :: toml
129+
130+ [tool.pytest.ini_options]
131+ pythonpath = "src"
132+
133+ .. note ::
134+
135+ If you do not use an editable install and not use the ``src `` layout (``mypkg `` directly in the root
136+ directory) you can rely on the fact that Python by default puts the current directory in ``sys.path `` to
137+ import your package and run ``python -m pytest `` to execute the tests against the local copy directly.
138+
139+ See :ref: `pytest vs python -m pytest ` for more information about the difference between calling ``pytest `` and
140+ ``python -m pytest ``.
123141
124142Tests as part of application code
125143^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0 commit comments