@@ -88,14 +88,6 @@ This has the following benefits:
88
88
89
89
* Your tests can run against an installed version after executing ``pip install . ``.
90
90
* 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 ``.
99
91
100
92
For new projects, we recommend to use ``importlib `` :ref: `import mode <import-modes >`
101
93
(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
120
112
121
113
.. _blog post : https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-structure>
122
114
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 ``.
123
141
124
142
Tests as part of application code
125
143
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0 commit comments